ravensshade Posted February 9, 2010 Share Posted February 9, 2010 hi i'm getting the following error SELECT mwa.Name,hw.Value FROM HardwareData AS hw FULL JOIN MachinesWithAgents AS mwa on hw.MachineID=mwa.MachineID WHERE mwa.Name LIKE EU\\MOON using this code: // removed login info for security MSSQL_CONNECT("") or DIE("DATABASE FAILED TO RESPOND."); mssql_select_db("SSISurvey") or DIE("Table unavailable"); $Name = str_replace ( "\\" ,"\", $_GET['name']); $query = "SELECT mwa.Name,hw.Value FROM HardwareData AS hw FULL JOIN MachinesWithAgents AS mwa on hw.MachineID=mwa.MachineID WHERE mwa.Name LIKE $Name"; however str replace doesn't seem to do anything.. Link to comment https://forums.phpfreaks.com/topic/191486-problem-with-str_replace/ Share on other sites More sharing options...
jl5501 Posted February 9, 2010 Share Posted February 9, 2010 The string replace as you have it, will do exactly nothing the backslash is an escape character to needs to be escaped itself so the best you are asking there is to replace a backslash with a backslash Not 100% sure on this one but this might work better $Name = str_replace ( "\\\\" ,'\', $_GET['name']); Link to comment https://forums.phpfreaks.com/topic/191486-problem-with-str_replace/#findComment-1009425 Share on other sites More sharing options...
ravensshade Posted February 9, 2010 Author Share Posted February 9, 2010 The string replace as you have it, will do exactly nothing the backslash is an escape character to needs to be escaped itself so the best you are asking there is to replace a backslash with a backslash Not 100% sure on this one but this might work better $Name = str_replace ( "\\\\" ,'\', $_GET['name']); well i do infact need a single backslash instead of 2 also your solution ends up in Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /nfs/atlas/web/sec/IS/surveytest/results.php on line 5 Link to comment https://forums.phpfreaks.com/topic/191486-problem-with-str_replace/#findComment-1009428 Share on other sites More sharing options...
Buddski Posted February 9, 2010 Share Posted February 9, 2010 Personally.. I would fix the input, if you can, for the GET variable.. itll be a hell of alot cleaner than doing this... In any case, this is how you need it.. as ugly as it is... str_replace ( "\\\\" ,"\\", $_GET['name']); Link to comment https://forums.phpfreaks.com/topic/191486-problem-with-str_replace/#findComment-1009429 Share on other sites More sharing options...
alexjb Posted February 9, 2010 Share Posted February 9, 2010 A tip for if there's more than one: $String = '/test//test///test////test/////test/test//test'; while(strpos($String, '//' ) <> 0) $String = str_replace('//', '/', $String); echo $String; Outputs '/test/test/test/test/test/test/test'. Link to comment https://forums.phpfreaks.com/topic/191486-problem-with-str_replace/#findComment-1009430 Share on other sites More sharing options...
ravensshade Posted February 9, 2010 Author Share Posted February 9, 2010 Personally.. I would fix the input, if you can, for the GET variable.. itll be a hell of alot cleaner than doing this... In any case, this is how you need it.. as ugly as it is... str_replace ( "\\\\" ,"\\", $_GET['name']); yeah i changed the statment str_replace ( "EU\\\\" ,"", $_GET['name']); and let the query search for ('%$Name%') alexjb: i noticed that aswell yes gonna fix that now knowhow to do that allready thanks for the help Link to comment https://forums.phpfreaks.com/topic/191486-problem-with-str_replace/#findComment-1009432 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.