URL ampersand issue

Hi,

I think this is the first time I’ve encountered such weird issue. I have a string store in the data like so “sale_&_marketing”

when I retrieve out the data and embed it to a link as a parameter and click on it, I get the following array:

var_dump($_GET);

array(2) {
[“pathInfo”]=> string(18) “/sales_”
[“_marketing”]=>
string(0) “”
}

It seems like breaking out the ampersand into 2?? :eek:

yep :agree:, it will because the ampersand is the normal delimeter between parameters in a query string appended to a url.

have a look at [FPHP]urlencode[/FPHP] and [FPHP]htmlentities[/FPHP]

$_GET and $_POST automatically decode encoded parameter values.

Thanks for your reply Kalon. Yes I did tried urlencode and got %26 in-replace for the ampersand for the thing is when I dump it again, I got the following:

array(1) {
[“pathInfo”]=> “/sales_”
}

It can’t seems to get to the rest of the %26_marketing part :injured:

think I’ve decided to replace the ampersand symbol to “and” for the seo url instead. Is this the normal way of doing it?

in this demo, formProcessor assigns the correct value to the $_GET value

index.php

 
 
<?php
$str = 'sales_&_marketing';
?>
 
<a href="formProcessor.php?txtInp=<?php echo urlencode($str) ?>">link to somewhere</a>
 

formProcessor.php

 
<?php
 
//echo htmlentities($_GET['txtInp'], ENT_QUOTES);
 
echo $_GET['txtInp'];
 
?>

the output from the echo is : sales_&_marketing

hmm it doesn’t work on mine. I just keep echo out “sales_” instead. I think most probably is the rewrite in my htaccess that break it. :frowning:

RewriteRule ^admin/view/(.+)$ admin/view.php?pathInfo=$1

could be :shifty:

I don’t have any real experience with htaccess files, but to test if that is your problem, can you rename your htaccess file to something else temporarily and then try the urlencode code again?

Quite literally impossible as the whole site’s url now is coded as /slash/blah/blah/. I would have to change alot of areas just to check on that, lol. But anyway really appreciate your help Kalon :slight_smile:

you’re welcome :slight_smile:

The problem has arisen because you are allowing a text string to be used almost as a variable.

If that title “Sales & Marketing” is coming from a user then you have to be prepared to enforce rigid rules about what is permitted in that title, replacing & with “and” is probably the easiest way round this.

I realise that then “Sales and Marketing” may not fit your menu systems etc, but that is the price you have to pay.

This whole free text as an SEO url or whatever is sometimes referred to as a “slugging” or creating a slug - if you wanted to get some algorithms to help you out on this.