Forum Moderators: coopster

Message Too Old, No Replies

Error in Print "Search Terms" script

         

WallyWorld

7:35 pm on Jul 24, 2005 (gmt 0)

10+ Year Member



I found this script in another thread that allows you to print to a webpage the search term that the visitor used to find your page - but I'm having trouble with it. The line:
"$var = ereg_replace("+"," ",$var); "
is giving me the following error on the page:
Warning: ereg_replace(): REG_BADRPT

Can anyone tell me what is wrong with that line? It tries to remove the "+" from between the search terms. If I take it out the script works but the "+" is between every word. Below is the full script.

if(!isset($HTTP_REFERER)){
print "General message goes here.";
}
else{
$query = split("[?]",$HTTP_REFERER);
$div = split("[&]",$query[1]);
foreach($div as $var){
if(preg_match("/q=/",$var)){
$var = ereg_replace("q=","",$var);
$var = ereg_replace("+"," ",$var);
print "So, you're looking for info about $var";
}
else{
}
}
}

mcibor

8:54 pm on Jul 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is because of the + sign, which has a meaning in ereg (not just as sign)

You can simply use normal
$var = str_replace [php.net]("+", " ", $var);

which is more straight forward and doesn't include any regex.

WallyWorld

12:08 am on Jul 25, 2005 (gmt 0)

10+ Year Member



Thanks, mcibor! That solved the problem.