Re: help with preg_replace only part of the string

From: Date: Tue, 06 Dec 2005 11:06:37 +0000
Subject: Re: help with preg_replace only part of the string
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-226912@lists.php.net to get a copy of this message
Georgi Ivanov wrote:
Hi, I want to replace the content of html links : <a href="foo" name="bla">REPLACETHIS</a>. $html=preg_replace("/(<a.*name=.*>)(.*)<\/a>/isU",$link,$html,1); This generally works but removes <a>,</a> tags too. How to make it work without removing anything else than (.*) in the middle of <a>.*</a>
$html = preg_replace("/(<a.*name=.*>)(.*)<\/a>/isU", '\1' . $link . '</a>', $html, 1); -- Richard Heyes http://www.phpguru.org

« previous php.general (#226912) next »