Jump to content


Photo

How do you use ereg() to obtain multiple results?


  • Please log in to reply
2 replies to this topic

#1 smithaa02

smithaa02
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 05 April 2006 - 04:18 PM

I need to find all id's inserted into a collection of html files and am wondering how to do it. For example, my files may contain:

<a href='/display.php?id=44'>link 1</a> ...html stuff... <a href='/display.php?id=1101'>link 1</a> ...html stuff... <a href='/display.php?id=999'>link 1</a>etc...

What I would hope to get as a result would be 44,1101,999.

I use the key display\.php\?id=([^"]+)" with ereg(), but I only get the first result. How would I get all the id's for each html file?

#2 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 05 April 2006 - 06:52 PM

[!--quoteo(post=361980:date=Apr 5 2006, 05:18 PM:name=smithaa02)--][div class=\'quotetop\']QUOTE(smithaa02 @ Apr 5 2006, 05:18 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I need to find all id's inserted into a collection of html files and am wondering how to do it. For example, my files may contain:

<a href='/display.php?id=44'>link 1</a> ...html stuff... <a href='/display.php?id=1101'>link 1</a> ...html stuff... <a href='/display.php?id=999'>link 1</a>etc...

What I would hope to get as a result would be 44,1101,999.

I use the key display\.php\?id=([^"]+)" with ereg(), but I only get the first result. How would I get all the id's for each html file?
[/quote]

have you tried 'preg_match_all' ?
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#3 smithaa02

smithaa02
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 06 April 2006 - 04:05 PM

[!--quoteo(post=362016:date=Apr 5 2006, 01:52 PM:name=redbullmarky)--][div class=\'quotetop\']QUOTE(redbullmarky @ Apr 5 2006, 01:52 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
have you tried 'preg_match_all' ?
[/quote]Thanks...that should do the trick.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users