Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-18-2012, 12:55 AM   PM User | #1
Mooseman
Regular Coder

 
Mooseman's Avatar
 
Join Date: Sep 2010
Posts: 118
Thanks: 7
Thanked 3 Times in 3 Posts
Mooseman is an unknown quantity at this point
Question Process URL parameter

I'd like to process a URL parameter, process it, and echo it. Here's an example:
Quote:
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 04:00 PM..
Mooseman is offline   Reply With Quote
Old 06-18-2012, 07:00 AM   PM User | #2
dan-dan
Regular Coder

 
dan-dan's Avatar
 
Join Date: Aug 2009
Location: England
Posts: 483
Thanks: 22
Thanked 79 Times in 78 Posts
dan-dan is on a distinguished road
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 07:07 AM..
dan-dan is offline   Reply With Quote
Old 06-18-2012, 03:59 PM   PM User | #3
Mooseman
Regular Coder

 
Mooseman's Avatar
 
Join Date: Sep 2010
Posts: 118
Thanks: 7
Thanked 3 Times in 3 Posts
Mooseman is an unknown quantity at this point
Thanks for your help! All is working!
Mooseman is offline   Reply With Quote
Reply

Bookmarks

Tags
php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:58 PM.


Advertisement
Log in to turn off these ads.