View Single Post
  #20 (permalink)  
Old 10-14-2007, 10:09 PM
venkat_charya venkat_charya is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 118
venkat_charya is on a distinguished road
Thumbs up Re: string functions and manipulations in php

As like addcslashes there is another string function available called addslashes().

It returns a string with backslashes before characters that need to be quoted in database queries etc. These characters are single quote ('), double quote ("), backslash (\) and NUL (the NULL byte).


For Example:
<?php
$str = "Is your name O'reilly?";
// Outputs: Is your name O\'reilly?
echo addslashes($str);
?>


Another Example
<?php
$str = "Who's Kai Jim?";
echo $str . " This is not safe in a database query.<br />";
echo addslashes($str) . " This is safe in a database query.";
?>
Ouput:
Who's Kai Jim? This is not safe in a database query.
Who\'s Kai Jim? This is safe in a database query.


Thanks
__________________
K K Venkata Charya
Success is easy to get but difficult to retain
Reply With Quote