note 105395 added to function.addslashes
| From: | boyaqb at gmail dot com | Date: | Sun, 14 Aug 2011 22:34:19 +0000 |
| Subject: | note 105395 added to function.addslashes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-182484@lists.php.net to get a copy of this message | ||
so you can use replace single quote and double quote with HTML Entities
for example
<?php
/**
* replcae quotes to HTML entities by names or numbers
*
* @param (string) escaped string value
* @param (string) default ='number' will be return to number entities you can use
='name' to return name entities
* Note : don't use ='name' coz (') (does not work in IE)
*/
function quote2entities($string,$entities_type='number')
{
$search = array("\"","'");
$replace_by_entities_name = array(""","'");
$replace_by_entities_number = array(""","'");
$do = null;
if ($entities_type == 'number')
{
$do = str_replace($search,$replace_by_entities_number,$string);
}
else if ($entities_type == 'name')
{
$do = str_replace($search,$replace_by_entities_name,$string);
}
else
{
$do = addslashes($string);
}
return $do;
}
echo quote2entities("I love 'PHP' for ever");
// will return I love 'PHP' for ever in browsere
// but in view code and database will be I love "PHP" for ever in source
?>
----
Server IP: 69.147.83.197
Probable Submitter: 178.53.25.6
----
Manual Page -- http://www.php.net/manual/en/function.addslashes.php
Edit -- https://master.php.net/note/edit/105395
Del: integrated -- https://master.php.net/note/delete/105395/integrated
Del: useless -- https://master.php.net/note/delete/105395/useless
Del: bad code -- https://master.php.net/note/delete/105395/bad+code
Del: spam -- https://master.php.net/note/delete/105395/spam
Del: non-english -- https://master.php.net/note/delete/105395/non-english
Del: in docs -- https://master.php.net/note/delete/105395/in+docs
Del: other reasons-- https://master.php.net/note/delete/105395
Reject -- https://master.php.net/note/reject/105395
Search -- https://master.php.net/manage/user-notes.php