bakedproject.com Blog Not just another WordPress weblog

28Dec/090

PHP end tag ?>

A lot of time web programmers make Ajax call to a PHP script to verify content(information). The PHP script usually have a true/false echo, (sometimes 1/0). The PHP script looks something like this

<?php
/* do some crazy validation and set $valid value */
 
if(!$valid) {
 echo "false"
} else {
 echo "true";
}
?>

This is all good and fun, but SFU when the interpretor reaches ?>! The PHP end tag prints a few CrLfs.

So the Ajax script having the following
if(msg=="true")
will always fail. So trim the Ajax output! Here is the trim function...

function trim(stringToTrim) {
 return stringToTrim.replace(/^\s+|\s+$/g,"");
}

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.