STR_Replace Spaces

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

STR_Replace Spaces

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Maybe it should be

Code: Select all

$sn = str_replace("%20", "", $get[0]);
(#10850)
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Cool, It worked. Thanks.
Post Reply