I have tag in my content. I need to replace all those tags by span tags: for eg: my contenti is wrapped like :
<blockquote><p>my content</p></blockquote>
.
I need to replace this with :
<span class="highlight">content</span>
How can i achieve this in PHP. I tried some preg_replace but nothing worked. Can anyone please help.
Thanks in advance.
try
preg_replace('/<blockqoute>.*?<p>(.*?)<\/p>.*?<\/blockqoute>/i', '<span class="highlight">$1</span>', $string);
$replace = preg_replace('/<blockqoute><p>(.*)<\/p><\/blockqoute>/i', '<span class="highlight">$1</span>', $subject); echo $replace;
- Edhen 2012-04-04 18:27
. How can we replace that as wel - Sabari 2012-04-04 18:40contennt
preg_replace('/<blockqoute>.*?<p>(.*)<\/p>.*?<\/blockqoute>/i', '<span class="highlight">$1</span>', $string);
Edhen 2012-04-04 18:46
Certainly not the best solution, but should be good enough and doesn't require regex:
$string = str_replace('<blockquote><p>', '<span class="highlight">', $string);
$string = str_replace('</p></blockquote>', '</span>', $string);
Alternatively:
$search = array('<blockquote><p>', '</p></blockquote>');
$replace = array('<span class="highlight">', '</span>');
$string = str_replace($search, $replace, $string);
tags inside the