kiki33 kiki33 - 7 months ago 14
PHP Question

PHP preg_replace dont work

I use this code:

$message = preg_replace("/<div style=\'background-color:#C0C8D0;width:95%;\'>SMA Forr&aacute;sk&oacute;d: <a href=\'\' onclick=\'selectcode((.*));return false;\'>[ Mindet kijelol ]<\/a><\/div><div id=\'(.*)\' style=\'width:95%;max-width:95%;max-height: 500px; overflow:scroll;background-color: #FFFFFF;\'><pre class=\'sma\' style=\'font-family:monospace;font-size: 12px;\'><ol><li style=\'font-weight: normal; vertical-align:top;\'><div style=\'font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\'>(.*)<\/div><\/li><\/ol><\/pre><\/div>/",'[sma]<pre>$3</pre>[/sma]',$message);


but it doesn't work. The original of html:

<div style='background-color:#C0C8D0;width:95%;'>SMA Forr&aacute;sk&oacute;d: <a href='#' onclick='selectcode(16351);return false;'>[ Mindet kijelol ]</a></div><div id='16351' style="width:95%;max-width:95%;max-height: 500px; overflow:scroll;background-color: #FFFFFF;"><pre class="sma" style="font-family:monospace;font-size: 12px;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">some-text</div></li></ol></pre></div>

Answer
$re = "/<div style='background-color:#C0C8D0;width:95%;'>SMA Forr&aacute;sk&oacute;d: <a href='#' onclick='selectcode\\((.*)\\);return false;'>\\[ Mindet kijelol \\]<\\/a><\\/div><div id='(.*)' style=\"width:95%;max-width:95%;max-height: 500px; overflow:scroll;background-color: #FFFFFF;\"><pre class=\"sma\" style=\"font-family:monospace;font-size: 12px;\"><ol><li style=\"font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\\/1\\.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">(.*)<\\/div><\\/li><\\/ol><\\/pre><\\/div>/"; 
$str = "<div style='background-color:#C0C8D0;width:95%;'>SMA Forr&aacute;sk&oacute;d: <a href='#' onclick='selectcode(16351);return false;'>[ Mindet kijelol ]</a></div><div id='16351' style=\"width:95%;max-width:95%;max-height: 500px; overflow:scroll;background-color: #FFFFFF;\"><pre class=\"sma\" style=\"font-family:monospace;font-size: 12px;\"><ol><li style=\"font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">some-text</div></li></ol></pre></div>\n"; 

preg_match($re, $str, $matches);