Hi
i have a php script that takes a url and loads all the code from that page into a variable.
I then want to scan through that variable and pick out the first 5 URLs. So i would need something which looks for the first 5 times that: \<a href=''http:// ----some url-----''> happens and store the occurances into different variables.
can anyone work it out? i'm very stuck
Genius Needed
Moderator: General Moderators
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Genius Needed
I'm no regex guru by any stretch of the word...but I htink thats what the curly braces are for, so instead of appending a + or ? after your URL match, you would use the {,5}
Just a guess
Just a guess
Re: Genius Needed
Two ways to tackle this situation pop up in my head. You could use preg_match_all() to match all URLs. Then just pick the first five out. Alternatively, you could put preg_match() in a loop. On every iteration you store the match and update the offset parameter. I'd go for the first method.