Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder Mooseman's Avatar
    Join Date
    Sep 2010
    Posts
    123
    Thanks
    7
    Thanked 3 Times in 3 Posts

    Question Process URL parameter

    I'd like to process a URL parameter, process it, and echo it. Here's an example:
    URL: example.com/file.php?item=set2image4
    echo: set2/image4
    URL: example.com/file.php?item=image6
    echo:set1/image6
    set1 would be inserted by default if set2 does not exist in the parameter. How can I process that with PHP? Thank you!
    Last edited by Mooseman; 06-18-2012 at 05:00 PM.

  • #2
    Regular Coder dan-dan's Avatar
    Join Date
    Aug 2009
    Location
    England
    Posts
    483
    Thanks
    22
    Thanked 79 Times in 78 Posts
    Think this should work.

    PHP Code:
    $item = (substr($_GET['item'], 03) != "set") ? "set1/".$_GET['item'] : substr($_GET['item'], 04)."/".substr($_GET['item'], 5);

    if (!
    file_exists($item)) {
       die (
    "Sorry, the file you are searhing for does not exist");
    }
    else {
       
    // Do something else

    Last edited by dan-dan; 06-18-2012 at 08:07 AM.

  • #3
    Regular Coder Mooseman's Avatar
    Join Date
    Sep 2010
    Posts
    123
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Thanks for your help! All is working!


  •  

    Tags for this Thread

    Posting Permissions

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