I pass a variable in which can have an & in it and it causes problems because the _GET[''] sees this as a new paramater name.
how can I avoid this
so if i have the following:
http://www.mydomain.com/search/index.php?ag_name=A & E Services&cat=9
the problem here is that A & E cuts and only A is passed through
string with & problem
Moderator: General Moderators
-
madan koshti
- Forum Commoner
- Posts: 50
- Joined: Fri Jun 06, 2008 4:25 am
Re: string with & problem
Refer urlencode() php function.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: string with & problem
Code: Select all
$ag_name = 'A & E Services';
$cat = 9;
$url = 'http://www.mydomain.com/search/index.php?ag_name=' . urlencode($ag_name) . '&cat=' . urlencode($cat);(#10850)
Re: string with & problem
I tried this but it never worked.
this is how i pass the the url through my .htaccess file
the .htaccess passes the 'a-&-e-estates-ltd' string to my search/index.php?searchtext=a-&-e-estates-ltd but only looks for 'a' and not 'a-&-e-estates-ltd'
so heres what I do to my string before I pass it into the query
simply replaces the - (dashes) with spaces and then makes sure only one space exists between a word.
The next stage is to manipulate any text if an & (amp) exists in the _GET['searchtext'] variable. How do I go about doing this?
this is how i pass the the url through my .htaccess file
Code: Select all
<a href="http://www.mydomain.co.uk/8630/uk/england/a-&-e-estates-ltd/a-&-e-estates-ltd-estate-agent-list.html">click</a>
so heres what I do to my string before I pass it into the query
simply replaces the - (dashes) with spaces and then makes sure only one space exists between a word.
The next stage is to manipulate any text if an & (amp) exists in the _GET['searchtext'] variable. How do I go about doing this?
Code: Select all
<?php
$_GET['searchtext'] = str_replace("-"," ",$_GET['searchtext']);
$_GET['searchtext'] = ereg_replace( ' +', ' ', $_GET['searchtext']);
?>
Re: string with & problem
You need to escape the ampersand.