Hi, I'm stuck with this problem (am not too familiar with reg exp)..... I have to find every href that is not ‘http://www.site1.com/ and remove the href link, but retain the link text.(Example : “<a href="http://www2.comune.roma.it/museociviltaromana/" class="external autonumber" title= "http://www2.comune.roma.it/museociviltaromana/"> humanoid </a>†replace with “ humanoid â€. Does anyone know the appropriate regular expression to do that.....? Thank you.
Try this $text = '<a href="http://www2.comune.roma.it/museociviltaromana/" class="external autonumber" title= "http://www2.comune.roma.it/museociviltaromana/"> humanoid </a>'; $patterns[0] = '/<a(.*?)>/si'; $patterns[1] = '/<\/a>/si'; $replacements[0] = ''; $replacements[1] = ''; echo preg_replace($patterns, $replacements, $text); PHP:
Thnx a lot.....Now, I have to remove all the links that's not 'http://www.site1.com/' from a text file. I'll try to tweak the regex to get it working.