Search:
Main Menu
Login | RSS |

Quick PHP Code Tips and Examples

PHP Programming Tips, Tutorials and Source Code Examples for newbie

Detect Alphabet only string with ctype_alpha

June 5th, 2008 by Jon Moffet

There are times when you need a function that can detect strings which contains onlyalphabetic characters. While is_numeric can validate a given string contains numeric character, there are no is_* function variation exist which can do the same for alphabetic strings.

However, you can still test for alphabetic string using ctype_alpha() function. Example usage :

CODE:
  1. if (ctype_alpha($testcase)) {
  2.         echo "The string $testcase consists of all letters.\n";
  3.     } else {
  4.         echo "The string $testcase does not consist of all letters.\n";
  5.     }
  6. }

Good luck, and happy coding.

Posted in Uncategorized | No Comments »

How to Truncate table in SQLite database

June 4th, 2008 by Jon Moffet

I found out that truncating SQLite database is a little bit different from its MySQL counterpart. Here's how to truncate SQLite database from command line

CODE:
  1. sqlite your_database.db
  2. sqlite> DELETE FROM some_table;

after that, dont forget to execute VACUUM to compact the database :

CODE:
  1. sqlite> VACUUM;

Posted in Uncategorized | No Comments »