Replace only part of a match using preg_replace?
Posted: Wed Jan 16, 2008 2:46 pm
Hey guys,
I researched a bunch and can't find the solution. Basically, I want to use preg_replace to find a string, and then replace *most* but not all of the string.
So, for instance, I tried this and it obviously doesn't work:
Any ideas?
I researched a bunch and can't find the solution. Basically, I want to use preg_replace to find a string, and then replace *most* but not all of the string.
So, for instance, I tried this and it obviously doesn't work:
Code: Select all
<?
$patterns[] = '/<td class="menu" onclick="javascript:window.location.href=\'(.*?)\';" onmouseover="this.className=\'menu2\';" onmouseout="this.className=\'menu\';">(.*?)<\/td>/';
$replacements[] = '<a id="12" href="(.*?)">(.*?)</a>';
$sHtml = preg_replace($patterns, $replacements, $sHtml);
?>