preg_replace problem
Can somebody please help me with what is happening here. I haven't used regular expressions much.
I have a string that is used to set up a link, [Link]http://www.somelink.com, my link text[/Link], within some content. I am needing to grab just the "my link text" for use elsewhere at one point. What is happening is that if I put my link tags in more than the results are the pattern is continuing to the last [/Link] tag and then remove some content. I just need to know how to get it to stop after the first [/Link] tag, I thought the .
$pattern = '@\[Link][^"]+,\ ?(.*?)\[/Link\]@';
$replacement = '\\1';
$strString2 = preg_replace($pattern, $replacement, $strString2);
$strString2 = "one [Link]http://www.linktwo.com, two[/Link] three four five six seven eight nine ten eleven";
// Results with one set of [Link] tags
//one two three four five six seven eight nine ten eleven
$strString2 = "one [Link]http://www.linktwo.com, two[/Link] three four five six [Link]http://www.linkseven.com, seven[/Link] eight nine ten eleven";
// Results with more than one set of [Link] tags
//one seven eight nine ten eleven
Thank You
Mike
__________________
Peace
Mike
http://www.eclecticpixel.com
|