note 76665 added to function.preg-replace
| From: | lehongviet at gmail dot com | Date: | Wed, 25 Jul 2007 08:15:29 +0000 |
| Subject: | note 76665 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128907@lists.php.net to get a copy of this message | ||
I got problem echoing text that contains double-quotes into a text field. As it confuses value
option. I use this function below to match and replace each pair of them by smart quotes. The last
one will be replaced by a hyphen(-).
It works for me.
function smart_quotes($text) {
$pattern = '/"((.)*?)"/i';
$text = preg_replace($pattern,"“\\1”",stripslashes($text));
$text = str_replace("\"","-",$text);
$text = addslashes($text);
return $text;
}
----
Server IP: 69.147.83.197
Probable Submitter: 203.162.33.222
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/76665
Del: integrated -- https://master.php.net/note/delete/76665/integrated
Del: useless -- https://master.php.net/note/delete/76665/useless
Del: bad code -- https://master.php.net/note/delete/76665/bad+code
Del: spam -- https://master.php.net/note/delete/76665/spam
Del: non-english -- https://master.php.net/note/delete/76665/non-english
Del: in docs -- https://master.php.net/note/delete/76665/in+docs
Del: other reasons-- https://master.php.net/note/delete/76665
Reject -- https://master.php.net/note/reject/76665
Search -- https://master.php.net/manage/user-notes.php