Friday, February 18, 2011

Escaping technique-PHP

Assalamu'alaikum and selamat sejahtera

Copy this one and run it:

<?PHP
$escape = 'Alex's pencil';
print $escape;

?>

it print error ryte?it is because PHP is confuse because this variable got three single quotes ,So,we need to remove one of  it but we still want to display "Alex's pencil" on the browser.So change this line :
$escape = 'Alex\'s pencil';

no error ryte? it is because,this variable got  this ' \ '.This ' \ ' is called escape(as i understand la..),so it tell the PHP to skip one character only after it.After ' \ ' is single quote ryte?So PHP skip it..so PHP said that variable got two single quote only!

N/NOTE:  $escape = "Alex\'s pencil"; use double quote also can maa,hahaha

No comments:

Post a Comment