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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    333
    Thanks
    2
    Thanked 47 Times in 46 Posts
    Use regular expressions or just good 'ol explode().

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

    $exploded explode('%'$pc);

    $new_pc $exploded[0]; //Will contain part before % 
    Last edited by Redcoder; 01-26-2013 at 02:08 PM. Reason: Error as noted below by Sunfighter

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,081
    Thanks
    23
    Thanked 592 Times in 591 Posts
    Error and correction this line:
    $new_pc = $exploded[0]; //Will contain part before %

    Need the 'd' to get the right variable.

  • #4
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've fixed it now..

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

    Thanks again for all your help.

    Cheers,
    David


  •  

    Posting Permissions

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