chelnov63 Posted April 6, 2009 Share Posted April 6, 2009 Hi when I pass a variable (which contains an ampersand) in a querystring it gives a problem.. example: $company = "B & Q"; <a href='companies/edit_company_details.php?company=<?php echo $company; ?>'>click here </a> but obviously the next page reads the company as being equal to 'B' How do I get around this? Thanks in advance.... Link to comment https://forums.phpfreaks.com/topic/152834-ampersand-in-querystring-problems/ Share on other sites More sharing options...
Mchl Posted April 6, 2009 Share Posted April 6, 2009 urlencode Link to comment https://forums.phpfreaks.com/topic/152834-ampersand-in-querystring-problems/#findComment-802586 Share on other sites More sharing options...
chelnov63 Posted April 6, 2009 Author Share Posted April 6, 2009 thank I actually tried that but it still doesnt work: this is the exact code: <a href="javascript:popUp('companies/edit_company_details.php?company=<?php echo urlencode($company); ?>')"><?php echo $row["company"]; ?></a> but when the new page opens the url in the top says: http://localhost/companies/edit_company_details.php?company=B+&+Q+Plc so it doesnt really look like its encoding the & symbol.... any ideas why this is so? cheers Link to comment https://forums.phpfreaks.com/topic/152834-ampersand-in-querystring-problems/#findComment-802599 Share on other sites More sharing options...
kenrbnsn Posted April 6, 2009 Share Posted April 6, 2009 Use rawurlencode instead. Ken Link to comment https://forums.phpfreaks.com/topic/152834-ampersand-in-querystring-problems/#findComment-802602 Share on other sites More sharing options...
chelnov63 Posted April 7, 2009 Author Share Posted April 7, 2009 Thanks Ken unfortunately still not working..it's strange as if i create a new php file and use urlencode it works fine, but for some reason in my context it's not doing it... i ended up using a hack instead: $company = str_replace("&", "|||", $company ); and then on the recieving page, i just reverse it: $company = str_replace("|||", "&", $_POST["company"]); thanks for your help anyway... cheers!! Link to comment https://forums.phpfreaks.com/topic/152834-ampersand-in-querystring-problems/#findComment-803237 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.