05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Query-string encoding<br />

The urlencode( ) and urldecode( ) functions differ from their raw counterparts only<br />

in that they encode spaces as plus signs (+) instead of as the sequence %20. This is the<br />

format for building query strings and cookie values, but because these values are<br />

automatically decoded when they are passed through a form or cookie, you don’t<br />

need to use these functions to process the current page’s query string or cookies. The<br />

functions are useful for generating query strings:<br />

SQL<br />

$base_url = 'http://www.google.com/q=';<br />

$query = '<strong>PHP</strong> sessions –cookies';<br />

$url = $base_url . urlencode($query);<br />

echo $url;<br />

http://www.google.com/q=<strong>PHP</strong>+sessions+-cookies<br />

Most database systems require that string literals in your SQL queries be escaped.<br />

SQL’s encoding scheme is pretty simple—single quotes, double quotes, NUL-bytes,<br />

and backslashes need to be preceded by a backslash. The addslashes( ) function<br />

adds these slashes, and the stripslashes( ) function removes them:<br />

$string =

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!