I'd like to change <pre>
with <code>
and </pre>
with </code>
.
I'm having problem with the slash / and regex.
I'd like to change <pre>
with <code>
and </pre>
with </code>
.
I'm having problem with the slash / and regex.
You could just use str_replace:
$str = str_replace(array('<pre>', '</pre>'), array('<code>', '</code>', $str);
If you feel compelled to use regexp:
$str = preg_replace("/<(\/)*pre>/", "<\\1code>", $str);
If you do one per tag:
$str = preg_replace("/<pre>/", '<code>', $str);
$str = preg_replace("/<\/pre>/", '</code>', $str);
You just need to escape that slash.
You probably need to escape the /s with \s, or use a different delimiter for the expression.
Instead, though, how about using str_replace? <pre>
and </pre>
will be easy to match as they're not likely to contain any classnames or other attributes.
$text=str_replace('<pre>','<code>',$text);
$text=str_replace('</pre>','</code>',$text);