
May 9th, 2007 by

Jon Moffet
This is an example of an enhanced contact form previously featured here and here . I've improved the contact form example to include Akismet spam protection in order to make it more resistant to spam attack.
Demonstration

The example includes :
- PHPMailer class for sending mail through your own SMTP server
- Akismet Anti-spam class
- Table-less contact form
Feel free to download the example to be used in your own application : plain_akismet.zip
Tags: contact form, php, php4, akismet, antispam, anti-spam, example, coding
Posted in Uncategorized |
2 Comments »

May 9th, 2007 by

Jon Moffet
Some web hosting provider such as e-ruang offers choices of using PHP4 or or PHP5 in their hosting. To avoid conflict with existing scripts, they will usually offer PHP 4 by default.
But for obvious reasons, you may want to use PHP5 as it supports more functionalities and more robust than PHP4. To enable PHP5 for your account, you need to create a .htaccess file containing :
CODE:
-
AddHandler application/x-httpd-php5 .php .php4 .php3 .phtml
Save the .htaccess file, and upload it to the root directory of your server.
Then upload a php file containing phpinfo() function to test whether PHP5 has been enabled or not. If the modification has not been successful then you should contact your web hosting provider and ask about the appropriate way to activate PHP5 functionality.
Tags: php5, php, web hosting, hosting
Posted in Uncategorized |
No Comments »

May 9th, 2007 by

Jon Moffet
Here is a well-written step-by-step tutorial on how to use SQLite in PHP 5. The tutorial was written by Ilia Alshanetsky and featured in Zend Developer Zone.
SQLite Introduction
For those who don't know, SQLite is a lightweight embedded database management system, it is available as the default database engine for PHP5. Due to its embedded nature, SQLite store its database on a single file and is significantly faster than MySQL. Backing up SQLite database is as simple as copying its database file to a backup media.
SQLite is an excellent choice for creating and deploying portable web application without the need to do complex db setups on target machines.
Tags: php, php5, sqlite
Posted in Uncategorized |
1 Comment »

May 4th, 2007 by

Jon Moffet
Truncate is a handy function which can truncate a long text into specific length string and adds elipsis (...) after it.
This is an example of how the function "truncate($text,47)" works :
Before
CODE:
-
This is a very long text that I type as an example to show you the functionality of truncate
After
CODE:
-
This is a very long text that I type as an exam....
Here's the PHP code that can let you do just that :
PHP:
-
function truncate ($str, $length=10, $trailing='...')
-
{
-
/*
-
** $str -String to truncate
-
** $length - length to truncate
-
** $trailing - the trailing character, default: "..."
-
*/
-
// take off chars for the trailing
-
-
-
{
-
// string exceeded length, truncate and add trailing dots
-
-
}
-
else
-
{
-
// string was already short enough, return the string
-
$res = $str;
-
}
-
-
return $res;
-
-
}
Truncate as an excerpt function
Truncate can be use to create excerpts from a very long text to serve as a preview or summary on your PHP application.
Tags: php, truncate, shorten, example, code, phpcode, tutorial
Posted in Uncategorized |
1 Comment »

May 3rd, 2007 by

Jon Moffet
Regular Expression (Regex, for short) is a very powerful feature in the PHP programming language. It is useful for manipulating strings using a set of well-defined rules.
However the often complex syntax rules used in Regex can prove to be a challenge to some. Thankfully, the folks at PHPGure has produced a nice and easy to read PCRE Cheat Sheet which contains commonly use Regex syntax like (\w) (\d) (\s) as a source of reference.
Download PCRE (Perl Compatible Regular Expression) Cheat Sheet (pdf) here
p/s: I've personally have the cheat sheet plastered on the wall of my room to remind me of the common regex shortcut (yes, I'm sucks at regex).
Tags: pcre, perl, php, regex, regular expression
Posted in Uncategorized |
2 Comments »