I have a string: <!--START name abc from domain.com.--> <a href="http://www.mysite.com"><img src="http://www.mysite.com" border="0"></a> <!--END MERCHANT:name abc from domain.com--> I want to replace everything between the start <!-- --> tags and also at the end I want to replace everything in the <!-- --> including the tags themselves. I tries using str_replace, but my problem is the abc is a variable so it keeps changing in every record.
$str = preg_replace('/<!--start.*?-->/i', '<p>replacement for START</p>', $str); Code (markup): Learn preg. It's the heart of the solution to a great many tasks.