I want a regex code , to replace all \"foo\" strings to \"bar\" , between the html tags pre>< /pre>
here is an example :
< html>
< p>
$string = '< html>
< p> blah blah blah foo try foo< /p>
< pre> foo try foo word foofoo < /pre>
< /html>';
$string = preg_replace('/foo(?=(?:.(?!< pre>))*< \/pre>)/Um', 'boo', $string);
echo $string;
You could use DOMDocument to extract the text content of your HTML tags, do a simple str_replace on the text and update the DOM.
First, go get Simple HTML Dom
// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');
// Find the first pre (you can change this or find an array based on documentation on website to suit your needs, but I will make it just for the first pre for now
$html->find('pre', 0)->plaintext = str_replace('foo', 'bar', $html->find('pre', 0)->plaintext);
//Echo HTML
echo $html;