Jump to content


Photo

preg_match to parse a post ID


  • Please log in to reply
2 replies to this topic

#1 wuwei101

wuwei101
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 05 July 2006 - 12:28 AM

hello,

Here's the code I have:

if (! PEAR::isError($req->sendRequest())) {
                if (preg_match('/edg176\/(\d+)/', $req->getResponseBody(), $matches)) {
                        $xangaPostID = $matches[1];

I am trying to parse the post ID number from my xanga page.  I am not sure why the (\d+) isn't working , since the post ID is simply everything after the edg176/.

The whole url usually looks like this:  http://www.xanga.com...76/nnn/xxx.html

I'm trying to get the nnn out of the posts.

Thanks


#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 05 July 2006 - 01:15 AM

That should work, but you want to use preg_match_all() to get all the values and then reference them like $matches[1][0], $matches[1][1], $matches[1][2], etc.


#3 wuwei101

wuwei101
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 07 July 2006 - 09:38 PM

Thanks.  I've read the documentation in the php manual for preg_match_all and I'm confused about what the set of 2 flags means.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users