Ampersand and $_GET
Moderator: General Moderators
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Ampersand and $_GET
Well I'm a bit stuck.
I've got it set up so that my client can list a bunch of clothing designers that they carry, and a few of them have an ampersand in their name. i.e. Dolce & Gabanna or J & Co.
This causes a problem in sending these variables through the URL, but it's been serving me so well
Is there a way to make the URL count it as a character rather than a separator?
I'm considering a forced preg_replace changing & to "amp;", but I'm hoping there's a more efficient solution.
I've got it set up so that my client can list a bunch of clothing designers that they carry, and a few of them have an ampersand in their name. i.e. Dolce & Gabanna or J & Co.
This causes a problem in sending these variables through the URL, but it's been serving me so well
Is there a way to make the URL count it as a character rather than a separator?
I'm considering a forced preg_replace changing & to "amp;", but I'm hoping there's a more efficient solution.
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
-
mikesmith76
- Forum Commoner
- Posts: 34
- Joined: Fri Aug 25, 2006 7:10 am
- Location: Manchester, UK
Just for future reference, wouldn't urlencode do the job?
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
& passed into a query string will go back to & but it will show in the source code as "&".
I have had a similar problem so I used str_replace to do the job:
I have had a similar problem so I used str_replace to do the job:
Code: Select all
$str = str_replace("&", "_", $str);
//or
$str = str_replace("&", "and", $str);
//you can have this into a function so you can use it when needed
function clean_url($str){
$str = str_replace("&", "_", $str);
//or
$str = str_replace("&", "and", $str);
return $str;
}- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Yeah, that's precisely my solution; replace the ampersands with "and." I was thinking it was possible to pass it through as an ampersand and use $_GET to get it as an ampersand after the send.
At the moment, I'm sending it through as "and" and displaying it as an ampersand. I really feel as though regex should have a method to using functions to format strings within
At the moment, I'm sending it through as "and" and displaying it as an ampersand. I really feel as though regex should have a method to using functions to format strings within
yes the is but you can not use it on the entire query string cause it will replace all the & and will trow an error
Is this what you are after:
did you look into RegExLib website: http://regexlib.com/default.aspx
Is this what you are after:
Code: Select all
$str = preg_replace ( "/\&/", "and", $str );//haven't test it- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm