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 01-26-2013, 12:20 PM   PM User | #1
davblackpool
New to the CF scene

 
Join Date: Jan 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
davblackpool is an unknown quantity at this point
Only certain letters from PHP Get Variable

Hi Everyone,

I'm new here, and struggling with trying to find an answer to my query.. Hopefully someone will be able to help?

I've got a GET variable from the URL on my web-page and I'm trying to get only certain letters/numbers before the % character.

Eg:

pc=FY1%201AA

I need that full pc variable for one section of my page, but for another section I'm hoping to be able to pull just the FY1 bit - but everything before the % sign.

Is this possible?

I've looked at getting the data changed at source, but it comes from a third party server and they are unable to help .

Thanks very much in advance.

Regards,
David
davblackpool is offline   Reply With Quote
Old 01-26-2013, 01:35 PM   PM User | #2
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
Use regular expressions or just good 'ol explode().

PHP Code:
$pc =$_GET['pc'];

$exploded explode('%'$pc);

$new_pc $exploded[0]; //Will contain part before % 
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk

Last edited by Redcoder; 01-26-2013 at 02:08 PM.. Reason: Error as noted below by Sunfighter
Redcoder is offline   Reply With Quote
Old 01-26-2013, 02:06 PM   PM User | #3
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,399
Thanks: 18
Thanked 352 Times in 351 Posts
sunfighter is on a distinguished road
Error and correction this line:
$new_pc = $exploded[0]; //Will contain part before %

Need the 'd' to get the right variable.
sunfighter is offline   Reply With Quote
Old 01-26-2013, 02:42 PM   PM User | #4
davblackpool
New to the CF scene

 
Join Date: Jan 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
davblackpool is an unknown quantity at this point
Hi Redcoder and sunfighter,

Thank you for helping me.. I've tried the code and can't get it going with the %20.

I think it might be reading it as a space and prints the full post-code.

I tried changing the % to a Q and put a Q in to the pc=FY1Q%201AA and that worked perfectly and gave me exactly what I needed.

Just trying to work a workaround now.

Thanks,
David
davblackpool is offline   Reply With Quote
Old 01-26-2013, 02:45 PM   PM User | #5
davblackpool
New to the CF scene

 
Join Date: Jan 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
davblackpool is an unknown quantity at this point
I've fixed it now..

Replaced the %20 with a simple space and it works great.

Thanks again for all your help.

Cheers,
David
davblackpool is offline   Reply With Quote
Reply

Bookmarks

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:51 AM.


Advertisement
Log in to turn off these ads.