Extract 9 Consecutive Numbers from URL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LuisAngel
    New Member
    • Apr 2010
    • 2

    #1

    Extract 9 Consecutive Numbers from URL

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



    The desired extraction is 312720263.

    Will the following work?

    Code:
    <?
    preg_match('/([0-9]{9})/', $alphanum, $matches);
    $sequence = $matches[1];
    ?>
    Thanks.
    Last edited by Dormilich; Apr 14 '10, 06:09 PM. Reason: Please use [code] tags when posting code
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Have you considered changing your query string to include an "id" parameter?

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

    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.

    Code:
    preg_match('/([0-9]{9}$)/', $alphanum, $matches)

    Comment

    • LuisAngel
      New Member
      • Apr 2010
      • 2

      #3
      You are right in that I don't have control over the query string.

      Comment

      Working...