Posts Under php Category
Send Email PHP Function
Ever find yourself typing the headers into the php mail() function over and over again? Try using a standard function and calling it when you need to send mail. function sendEmail($subject,$content,$from,$to){ $header = “Content-Type: text/html; charset=iso-8859-1\nFrom:$from”; if( mail($to, $subject, $content, $header) ); }
PHP __autoload function
When PHP encounters a class that hasn’t been defined yet, you can use __autoload to iautomatically add them instead of including masses of included at the top of your files. e.g. function __autoload($class_name) { require_once $class_name . ‘.php’; }
Sending data from javascript to php
If you ever find yourself needing to do some ajax and in turn sending strings of characters via javascript then you should really try encodeURIComponent() to wrap your strings in. The function escape() can also be used, but I would not recommend it as encodeURIComponent() is better, it also escapes your usual ampersand ajax limiters which solved me quite a bit of pain.
Uppercase the first character of each word in a string
You can use “ucwords()” to uppercase the first character of each word in a string. e.g. $myVar = ‘this is a test!’; $myVar = ucwords($myVar); // This Is A Test!
expecting T_PAAMAYIM_NEKUDOTAYIM
What the hey? What does this mean? You may one day end up seeing the following error message produced by PHP and wonder to yourself: PHP Parse error: syntax error, unexpected ‘)’, expecting T_PAAMAYIM_NEKUDOTAYIM in /*/*/File.php on line 160 You guessed it, “T_PAAMAYIM_NEKUDOTAYIM” is not english. It’s actually a Hebrew word meaning “unexpected” or “Twice Colon“. It happens when PHP tries to call the “::” (double colon) which is used…