Extract numbers from url

Discussion in 'PHP' started by WhatiFind, Mar 7, 2005.

  1. #1
    I want to extract numbers from an array, the array is an url. The url is for instance www.hostname.com/dir/47.php or /dir/1324.php and so on. The code I made works fine by doing this, but I'm no PHP wizkid.

    Is there a more easy way to extract the numbers from the url?

    Here is the code I made:
    <?
    $dir = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    $link = eregi_replace("www.hostname.com/dir/", "", $dir);
    $no = eregi_replace(".php", "", $link);
    require_once("http://www.hostname.com/dir/index.php?c=$no");
    ?>
    Code (markup):

     
    WhatiFind, Mar 7, 2005 IP
  2. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'd do this..
    
    $no = substr(basename($_SERVER['PHP_SELF']),0,-4);
    require_once("http://www.hostname.com/dir/index.php?c=$no");
    
    PHP:
     
    exam, Mar 7, 2005 IP
  3. WhatiFind

    WhatiFind offline

    Messages:
    1,789
    Likes Received:
    257
    Best Answers:
    0
    Trophy Points:
    180
    #3
    Great! Thanks exam
     
    WhatiFind, Mar 7, 2005 IP