Blog Not just another WordPress weblog


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

/* 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
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


No trackbacks yet.