0

I have a URL that contains a department name that will pull records from the database.

The URL looks like this: submissions.php?department=Settings,%20Security%20&%20Payments which is the equivalent of Settings, Security & Payments

My query needs to pull records from the table where the department is equal to Settings, Security & Payments.

How can convert that GET variable back to what I would expect it to be?

I tried html_entity_decode but it ignores the & and only gave me everything prior to that.

Whats the best way to do that?

Side note, if it was my data I would make it simple and pull it by ID but we dont have a table that has ID's for the departments.

6
  • 1
    That url's badly constructed anyways. Why encode the spaces and then leave the & alone? Whatever code is generating that should be fixed. Commented Aug 29, 2014 at 15:19
  • Try encoding the ampersand to %26. PHP may be interpreting %20Payments as another parameter in your querystring since it does follow an ampersand. I bet if your did print_r($_GET) you would see an additional parameter you weren't expecting. Commented Aug 29, 2014 at 15:20
  • @MarcB that is just how the value is stored in the database. I have a filter that allows you to pull records by department and unfortunately that's how some of the departments are formatted. Commented Aug 29, 2014 at 15:21
  • fact remains, that the url's bad. if you wanted a literal & in the url, then it should be %26. Leaving is as & makes the browser think it's a query argument separator. Commented Aug 29, 2014 at 15:22
  • 1
    Do a urlencode on the string before it is added to the URL. Then do a urldecode when you get it on the other side. This will effectively double encode it (since it is already partially encoded in the database) and double decode it. Commented Aug 29, 2014 at 15:45

3 Answers 3

2

Try urldecode()

You can see the manual here. https://www.php.net/urldecode

Sign up to request clarification or add additional context in comments.

1 Comment

"The superglobals $_GET and $_REQUEST are already decoded." It returned the same thing as entity_decode
1
<?php

$string = "submissions.php?department=Settings,%20Security%20&%20Payments";
$decoded = urldecode($string);

echo "Original string: $string\n";
echo "Decoded string: $decoded\n";

?>

http://codepad.org/Bq1Gt30s

Comments

0

Use urldecode($your_URLstring)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.