Re: help with preg_replace only part of the string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 07:06 AM 12/6/2005, Richard Heyes wrote:
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

If you know what you are replacing, i.e. REPLACETHIS is a placeholder, str_replace() or substr_replace() are much simpler.

Miles Thompson

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux