Jump to content

[SOLVED] $_GET not working as expected when getting %Beach%


brynkaufman

Recommended Posts

That's because the "%" character followed by another 2 characters is interpreted as an urlencoded character when it's on the URL and PHP is receiving the decoded value. You can reencode it:

<?php
$test = urlencode($_GET['test']);
?>

 

Ken

You need to encode it before putting it into the url.

 

Test script:

<?php
if (isset($_GET['test']))
    echo $_GET['test'], '<hr>';
?>

<a href='?test=%beach%'>TEST 1</a>
<br>

<?php
$test = urlencode('%beach%');
echo "<a href='?test=$test'>TEST 2 </a>";
?>

Sorry, I should have mentioned I tried to urlencode and this is what I get.

 

echo urlencode($_GET['test']);

 

gives %BEach%25 

 

Notice the 25 after the last percent sign.  I am trying to pass this search parementer - %Beach% - for MySQL through the URL so I can't have anything after the % or it won't find the right results.

 

Also, the % is not intended to be a space, it is the wildcard for the search so anything with the word Beach in it will come back in the results.

Thanks Ken,

 

I will just use * as my wildcard and change it to a % in the script.  This seems to work fine.  I thought there might be some function to get the % working but using a * for a wildcard will be even more familiar to my users.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.