By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,700 Members | 1,466 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,700 IT Pros & Developers. It's quick & easy.

Extract 9 Consecutive Numbers from URL

P: 2
How do I extract 9 consecutive numbers from URLs like the following:

http://itunes.apple.com/us/app/redla...312720263?mt=8

The desired extraction is 312720263.

Will the following work?

Expand|Select|Wrap|Line Numbers
  1. <?
  2. preg_match('/([0-9]{9})/', $alphanum, $matches);
  3. $sequence = $matches[1];
  4. ?>  
Thanks.
Apr 14 '10 #1
Share this Question
Share on Google+
2 Replies


Frinavale
Expert Mod 5K+
P: 9,731
Have you considered changing your query string to include an "id" parameter?

So you'd have something like:
"http://itunes.apple.com/us/app/redlaser/id312720263?mt=8&id=312720263"

You don't have control over the query string do you.
Well in this case I'd take the last 9 digits in the URL.
The "$" is used to to indicate the end of the string...

So, the following will work so long as you $alphanum variable contains the URL.

Expand|Select|Wrap|Line Numbers
  1. preg_match('/([0-9]{9}$)/', $alphanum, $matches)
Apr 14 '10 #2

P: 2
You are right in that I don't have control over the query string.
Apr 14 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.