note 76665 modified in function.preg-replace by danbrown

From: Date: Fri, 28 Nov 2008 19:52:54 +0000
Subject: note 76665 modified in function.preg-replace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147151@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. <?php function smart_quotes($text) { $pattern = '/"((.)*?)"/i'; $text = preg_replace($pattern,"“\\1”",stripslashes($text)); $text = str_replace("\"","-",$text); $text = addslashes($text); return $text; } ?> --was-- 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,"&#147;\\1&#148;",stripslashes($text)); $text = str_replace("\"","-",$text); $text = addslashes($text); return $text; } http://php.net/manual/en/function.preg-replace.php

« previous php.notes (#147151) next »