Hello all,

A script we are working on deals with passing file names in the URL (via $_GET). Some files contain the '&' symbol in the name.

& is the separator in PHP to identify the new $_GET variable.

We typically use urlencode($theString) to encode 'funny' characters to be URL safe. However, PHP seems to treat the encoded '&' value in exactly the same way as if it were not encoded.

Here is an example of the problem.

File name is Q&A.jpg

The script may be like this

<?php
$fileName = $_GET[fileName];
echo $fileName;
?>

If the url in the browser was script.php?fileName=Q&A.jpg, the output would be Q.

If you url encode the file name, the url would appear as script.php?fileName=Q%26A.jpg

However the output is still just Q without the '&A.jpg'.

Similarly, we have tried using rawurlencode, but this does not fix the problem either.

Anyone familiar with this problem and know a fix?
FShoppe Reviewed by FShoppe on . PHP problem handling urlencoded '&' (%26) char Hello all, A script we are working on deals with passing file names in the URL (via $_GET). Some files contain the '&' symbol in the name. & is the separator in PHP to identify the new $_GET variable. We typically use urlencode($theString) to encode 'funny' characters to be URL safe. However, PHP seems to treat the encoded '&' value in exactly the same way as if it were not encoded. Here is an example of the problem. Rating: 5