Page 1 of 1

STR_Replace Spaces

Posted: Fri Feb 03, 2006 4:54 pm
by nickman013
Hello,

I had a tracking script that stored the data to a file using fwrite.

I have recreated my script that stores it onto a database.

track.php

Code: Select all

<?php
$page = "home";
$username= "muot_track";  
$password= "password";  
$database= "muot_tracker";  
$connection = mysql_connect('localhost',$username,$password);  
mysql_select_db($database); 
$get=array(); 
foreach(explode('|',$_SERVER['QUERY_STRING']) as $get) { 
     $get = explode('-',$get); 
     $my_get[$get[0]]=$get[1]; 
} 
$sn = str_replace(" ", "", $get[0]);
if ($_SERVER['REMOTE_ADDR']  != '68.195.158.8') 	{
if ($sn  != '') 						{
$date = date("m.d.y");
$time = date('g:i a',time()+3600);
$ip = @$REMOTE_ADDR; 
$sql = "INSERT INTO  `Tracker` (  `Number` ,  `Screen Name` ,  `Page` ,  `Date` ,  `Time` ,  `IP` ) 
VALUES (
'',  '$sn',  '$page',  '$date',  '$time',  '$ip'
);
";
$result = mysql_query($sql) or die(mysql_error()); 


													}
										}
echo $sn;
?>
Everything works fine but the problem I am having is that if the $sn variable contains spaces it puts in %20 for a space, I have a STR_Replace function in there, that should do the job. But it doesnt.

Anybody know what is wrong?

Posted: Fri Feb 03, 2006 4:56 pm
by Christopher
Maybe it should be

Code: Select all

$sn = str_replace("%20", "", $get[0]);

Posted: Fri Feb 03, 2006 5:04 pm
by nickman013
Cool, It worked. Thanks.