preg_replace: literal "/" in pattern string
| From: | ROBERT MCPEAK | Date: | Mon, 02 Jun 2003 19:18:30 +0000 |
| Subject: | preg_replace: literal "/" in pattern string | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-149833@lists.php.net to get a copy of this message | ||
Search through the docs/archive and can't figure this one out. Surely I'm overlooking
something obvious.
I can't figure out how to escape a literal "/" in $q. Adding the line:
$q=str_replace("/", "\/", $q); yields a literal "\/" in $content.
$q_upper=strtoupper($q);
$q_lower=strtolower($q);
$q_ucfirst=ucfirst($q);
$patterns[0] = "/$q/";
$patterns[1] = "/$q_upper/";
$patterns[2] = "/$q_lower/";
$patterns[3] = "/$q_ucfirst/";
$content = preg_replace($patterns, $replacements, $content);
Thanks in advance, sincerely!