Page 1 of 1

string with & problem

Posted: Tue Jul 22, 2008 3:30 am
by gurjit
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

Re: string with & problem

Posted: Tue Jul 22, 2008 4:19 am
by madan koshti
Refer urlencode() php function.

Re: string with & problem

Posted: Tue Jul 22, 2008 4:23 am
by Christopher

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);

Re: string with & problem

Posted: Tue Jul 22, 2008 5:18 am
by gurjit
I tried this but it never worked.

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>
 
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?

Code: Select all

 
<?php
$_GET['searchtext'] = str_replace("-"," ",$_GET['searchtext']);
$_GET['searchtext'] = ereg_replace( '  +', ' ', $_GET['searchtext']);
?>
 

Re: string with & problem

Posted: Tue Jul 22, 2008 9:10 am
by LSJason
You need to escape the ampersand.