Can anyone, please help me with a reg exp for this: <pre style="color: red"> <?php phpinfo(); ?> </pre> I want to look for the first pre tag and for the second one, take only what is between those and to replace all < > tags with > and < . Thank you.
Something like that will transform $text into what you desire. preg_match('@(<pre(?:>|\s[^>]*?>))(.*?)(</pre>)@ims',$text,$res); $replace=array('>','<'); $search=array('|>|','|<|'); $newtext=preg_replace($search,$replace,$res[2]); PHP: or preg_match('@(<pre(?:>|\s[^>]*?>))(.*?)(</pre>)@ims',$text,$res); $newtext=htmlentities($res[2]); PHP: