Results 1 to 3 of 3

Thread: An Alternative to array_shift and explode? - Please Help

Hybrid View

  1. #1

    Question An Alternative to array_shift and explode? - Please Help

    Hey,

    array_shift seems to work on another server, but it does not on mine.

    The code is the following;

    PHP Code:
    $realid array_shift(explode("-"$id)); 
    What I am trying to get done is the following;

    I have a URL, which is like [ example.com/48555-animal-name.html ]. How is it possible to ONLY get the ID which is 48555, to call an entry from the database?

    PHP Code:
    $realid array_shift(explode("-"$id));
    $qryrec="select * from animals where id='$realid'";
    $resultrec=mysql_query($qryrec) or die($qryrec);
    $linerec=mysql_fetch_array($resultrec);
    $pcommon ucwords($linerec[common]); 
    Is there an another way of doing this, without using array_shift?

    Thanks,

  2. #2
    Your example should work if $id = "48555-animal-name.html" since array_shift is available in PHP 4 and PHP 5.

    I suspect that the value stored in $id has something before the id number.

    This should work as long as the id is the only part of the url containing numbers:
    PHP Code:
    $realid preg_replace('@[^0-9]@'''$id); 

  3. #3
    Great! - Thanks buddy

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •