Do you have a question? Post it now! No Registration Necessary. Now with pictures!
July 5, 2005, 1:50 pm
rate this thread
I need to be able to search a text field and grab every instance of a
string that falls between <tag class="name"> and </tag>.
We can assume that the tags will always be written properly.
So if the following is my text field: "They streamed across the Clemente
Bridge, docked along the <tag class="name">Allegheny River</tag>, strolled
from the North Side and biked down the trail to watch their Pirates. <br/>
They filled <tag class="name">PNC Park</tag> to the last sliver of
standing-room space on the rotunda, <tag class="name">37,259</a> strong.
<br/> And they came in full throat, chanting and cheering from the outset."
...I'd need the code to return, probably an array, like this:
$array = Allegheny River
$array = PNC Park
$array = 37,259
I just can't get it. Any suggestions?
[ Sugapablo ]
[ http://www.sugapablo.net <--personal | http://www.sugapablo.com <--music ]
[ http://www.2ra.org <--political | http://www.subuse.net <--discuss ]
Re: regex help
So why did you make an error in your example? :)
Tell us where you are running into problems. It's really simple if:
-you know the correct function
-you know your regexpes.
Do you want to learn how to do it or do you just want the answer of how
to get an array like:
 => Array
 => <tag class="name">Allegheny River</tag>
 => <tag class="name">PNC Park</tag>
 => <tag class="name">37,259</tag>
 => Array
 => Allegheny River
 => PNC Park
 => 37,259
If you want to learn see
http://nl2.php.net/manual/en/function.preg-match-all.php (the examples
contain samples that match your question closely) and
greedy vs. non greedy)
The spoiler is below:
- » Script to determine valid email address by querying server
- — Previous thread in » PHP Scripting Forum