blufish Posted November 23, 2008 Share Posted November 23, 2008 I need to write a piece of code like: str_replace("\","",$_POST['userinput']) but I can't write \ or it messes up, how can I do this? I already tried strip slashes but that doesn't get rid of every \ only some of them. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/133885-escape/ Share on other sites More sharing options...
ratcateme Posted November 23, 2008 Share Posted November 23, 2008 str_replace("\\","",$_POST['userinput']) will do it Scott. Quote Link to comment https://forums.phpfreaks.com/topic/133885-escape/#findComment-696926 Share on other sites More sharing options...
blufish Posted November 23, 2008 Author Share Posted November 23, 2008 Thanks, What if I need to delete a file with \ in it? the file is invalid so it won't let me delete. Please help. Quote Link to comment https://forums.phpfreaks.com/topic/133885-escape/#findComment-696932 Share on other sites More sharing options...
ratcateme Posted November 23, 2008 Share Posted November 23, 2008 when ever you want a backslash in php you need to \\ the first one escapes the second one so it can't escape the next character. here is a list of escapable characters http://nz.php.net/manual/en/language.types.string.php#language.types.string.syntax.double Scott. Quote Link to comment https://forums.phpfreaks.com/topic/133885-escape/#findComment-696933 Share on other sites More sharing options...
blufish Posted November 23, 2008 Author Share Posted November 23, 2008 The real problem is that I have a file like "bla\ bla \" and its not a valid file name, so I can't delete it and I need to delete it can you help? Quote Link to comment https://forums.phpfreaks.com/topic/133885-escape/#findComment-696936 Share on other sites More sharing options...
Mchl Posted November 23, 2008 Share Posted November 23, 2008 How can you have such a file, if there can not be such a file??? Quote Link to comment https://forums.phpfreaks.com/topic/133885-escape/#findComment-696939 Share on other sites More sharing options...
ratcateme Posted November 23, 2008 Share Posted November 23, 2008 have you tried unlink("bla\\ bla \\"); that should work i think??? Scott. Quote Link to comment https://forums.phpfreaks.com/topic/133885-escape/#findComment-696941 Share on other sites More sharing options...
ratcateme Posted November 23, 2008 Share Posted November 23, 2008 How can you have such a file, if there can not be such a file??? yea i didn't think it would be possible to create a filename containing a \ but on my linux box i went "vi test\\" and i allowed it and created "test\" Scott. Quote Link to comment https://forums.phpfreaks.com/topic/133885-escape/#findComment-696942 Share on other sites More sharing options...
Mchl Posted November 23, 2008 Share Posted November 23, 2008 yea i didn't think it would be possible to create a filename containing a \ but on my linux box i went "vi test\\" and i allowed it and created "test\" Scott. Yikes! The world suddenly seems less safe to me. Quote Link to comment https://forums.phpfreaks.com/topic/133885-escape/#findComment-696943 Share on other sites More sharing options...
ratcateme Posted November 23, 2008 Share Posted November 23, 2008 well i just tried the same thing on a windows share and it failed and wouldn't write the file. Scott. Quote Link to comment https://forums.phpfreaks.com/topic/133885-escape/#findComment-696945 Share on other sites More sharing options...
blufish Posted November 23, 2008 Author Share Posted November 23, 2008 if was just a file_put_contents and it worked... of course I didn't mean to do it, it was user input. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/133885-escape/#findComment-696959 Share on other sites More sharing options...
trq Posted November 23, 2008 Share Posted November 23, 2008 If the file really is called "test\" just use.... rm test* to remove it. Quote Link to comment https://forums.phpfreaks.com/topic/133885-escape/#findComment-696972 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.