I have a script that turns certain words into links. That I am having
no problems with, it is when I want to turn the links back in to plain
text that I am having the problem. Below are my examples. And I know
my regex is being greedy but I don't know how to stop it from being so
damn greedy I thought the ? mark would help but it didn't. Any help
would be appreciated. So here it goes:
The code:
$strStr = "This is <a href=test>USF</a> at <a href=test>Tampa</a>. This
is <a href=test>USF</a> at <a href=test>Tampa</a>.";
echo $strStr."<br>\n";
$strStr = preg_replace("/<a.*?>(Tampa)<\/a>/","\\1",$strStr);
echo $strStr."<br>\n";
$strStr = preg_replace("/<a.*?>(USF)<\/a>/","\\1",$strStr);
echo $strStr."<br>\n";
The output:
This is <a href=test>USF</a> at <a href=test>Tampa</a>. This is <a
href=test>USF</a> at <a href=test>Tampa</a>.
This is Tampa. This is Tampa.
This is Tampa. This is Tampa.
The expected output:
This is <a href=test>USF</a> at <a href=test>Tampa</a>. This is <a
href=test>USF</a> at <a href=test>Tampa</a>.
This is <a href=test>USF</a> at Tampa. This is <a href=test>USF</a> at
Tampa.
This is USF at Tampa. This is USF at Tampa.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
- [PHP] Re: Regular Expression Help in my PHP! Sorry if ... Jason Lehman
- [PHP] Re: Regular Expression Help in my PHP! Sorr... Jason Lehman
- Re: [PHP] Regular Expression Help in my PHP! Sorr... 1LT John W. Holmes
- Re: [PHP] Regular Expression Help in my PHP! ... Jason Lehman