Jason Lengstorf was nice enough to offer our community a handful of copies of his latest awesome book, Pro PHP and jQuery. Be sure to read his latest Nettuts+ tutorial, “Object-Oriented PHP for Beginners,” based on his book.
Winners Announced:
Congratulations to the following winners, who were randomly selected:
- Jonathan Stuckey
- Rick Blalock
- Matt Vickers
Each of you will be contacted shortly about arranging your free copy. Thanks again to everyone who entered!
“This book is for intermediate programmers interested in building Ajax web applications using jQuery and PHP. Along with teaching some advanced PHP techniques, it will teach you how to take your dynamic applications to the next level by adding a JavaScript layer with jQuery.”
To enter for a chance to win a hardcopy version of the book, leave a comment with a PHP tip. It can be as simple or as long as you like. Just as long as it was something that helped you to learn PHP, that will automatically enter you! On Monday morning, we’ll choose the winners!
You can also purchase “Pro PHP and jQuery” here.

If you want to merge arrays and want to keep your array keys, don’t use array_merge but just use plus:
$myArray = $array1 + $array2 + $array3;
I used rand() function to show one random banner at a time on my site.
It’s just what I need!!!
I always now split my code up into manageable functions in a separate file and make the most of includes and requires to increase efficiency.
Also avoid using loads of nested if else statements because it just gets complicated, use cases.
This book looks fantastic! I have just finished the PHP Live course over at Sitepoint and this would take it to the next step!
use mysql_real_escape_string to filter incoming information in mysql query.
use addslashes to avoid simple mysql error with incoming information which have characters that need to be quoted. I really like your book so i will buy one.
$objDirectoryFiles = new DirectoryIterator($path) ;
foreach ($objDirectoryFiles as $file){
if ($file->isFile()){
if ((strripos($file,”.jpg”)==true) || (strripos($file,”.gif”)== true)) {
array_push($arrFileName,’images/game/’.$file->getFileName());
}
}
}
I want to improve my skills of jquery and php, so i realy want to read this book.
Helven needs the book!
i really want to read this book.
Don’t close your PHP documents with ?>
The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include() or require(), so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later. It is also handy if you use output buffering, and would not like to see added unwanted whitespace at the end of the parts generated by the included files.
You can use this php code for endless counting. It continues with the first item when reaching the last. You never have to reset the counter :)
function endless($array, $item = 0){
return $array[$item % sizeof($array)];
}
Just use this if you want to check a array, $_POST,$_GET,$_FILES and such which is nice to see what happens. Also can be implemented into classes and such…
function smartDebugger($obj)
{
echo “”;
print_r($obj);
echo “”;
}
on ajax calls to a php file – use jquery $.ajax function and in dataType set “JSON” ($.ajax({dataType:’json’,'url….). Then in the php file in when echoing result – you create an array(‘status’=>’success’, ‘message’=>MESSAGE YOU WANT TO RETURN ON AJAX CALL) then you do echo json_encode(ARRAY_THAT_YOU_JUST_CREATED); So now on ajax call the javascript file can parse this json returned string and check what was the status of request and if its “success” show the message of success , otherwise show Error message, which you can also pass from php.
If you’re using regular expressions, then ereg_replace() and preg_replace() will be much faster than str_replace().
If you need to perform an arithmetic operation on a $_POST string variable, use intval($_POST['varName']) or (int)$_POST['varName']…
I really want to read this book. the tutorial was fantastic
Looking at wordpress codings is a good way to start learning about php syntaxes. they are very quite and straight to the point.
If for whatever reason you require the use of another framework like MooTools remember to use jQuery.noConflict(); to prevent conflicts in your scripts.
// returns no. of minutes between given hours
function calculMinutesFromHours($Time1, $Time2) {
$totalMinutes = 0;
$startTime = $Time1;
$endTime = $Time2;
$startMinute = substr($startTime, 3, 2);
$endMinute = substr($endTime, 3, 2);
$difHours = substr($endTime, 0, 2) – substr($startTime, 0, 2);
if($difHours == 0) {
$totalMinutes += abs(($endMinute-$startMinute));
}
if($difHours > 0) {
$totalMinutes += ((60*$difHours)-$startMinute) + $endMinute;
}
return $totalMinutes;
}
would love to pic up that book …
test early and test often!
This is from Robin Nixon’s book “PHP, MySQL & Javascript”, to sanitize user input from a form:
function sanitizeString($var)
{
$var = stripslashes($var);
$var = htmlentities($var);
$var = strip_tags($var);
return $var;
}
I’ve found it very useful.
For great code, almost never copy and paste.
Congrats… Way to throw your comment in there last minute Jonathan – Seems to have worked out lol!
lol – yepp the very last comment of 818 entries wins again. Mmmm, JW – check your rand() function will ya! ;)
Good Job , im not a Member yet But In the Futures :) Lol
omg thats not right, can you explan how its randomly selected???
that sux
function youWin($name) {
if($name == ‘Anthony’) {
return “win !”
}
else return “Loooose”;
}
Here 2 of my utility functions…
/* PHP Email verification */
if(!eregi(“^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$”, $email)) {
print “Invalid Email [$email] \n”;
}
/* Javascript’s parseInt in php */
function parseInt($string) {
// return intval($string);
if(preg_match(‘/(\d+)/’, $string, $array)) {
return $array[1];
} else {
return 0;
}
}
Love coding in jQuery and PHP – would love to get the book…
muchas gracias a todo por todos