Jump to content

Archived

This topic is now archived and is closed to further replies.

wuwei101

preg_match to parse a post ID

Recommended Posts

hello,

Here's the code I have:

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

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/edg176/nnn/xxx.html

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

Thanks

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.