Ziph Posted September 17, 2008 Share Posted September 17, 2008 Hello I put a filelink + filename in my database that contains spaces i want to remove those with this php script. I send the filelink from the the previous page to this one with a header sending the filename with it in a $msg= $filename = $_GET["msg"]; $filelinkconstruct = mysql_query("SELECT filelink FROM uploads WHERE username='$username' AND filename='$filename' "); while($fix = mysql_fetch_assoc($filelinkconstruct)) { $mustfixlink = $fix['filelink']; }; $fixedlink = preg_replace('[([\r\n])[\s]+]', '_', $mustfixlink); /// it wont replace the whitespaces with _ i tried a lot of diffrent space codes but for some reason it wont work echo "$fixedlink = fixedlink"; echo "$mustfixlink = mustfixlink"; EXAMPLE: http://www.gosuhosting.com/upload/fixfilename.php?msg=x%20s%20a.png IN DATABASE = filelink "http://www.gosuhosting.com/upload/Ziph/x s a.png" and filename "x s a.png" RESPONSE: http://www.gosuhosting.com/upload/Ziph/x s a.png = fixedlink http://www.gosuhosting.com/upload/Ziph/x s a.png = mustfixlink im pretty sure there must be something wrong with the pregreplace code but i cant find what i should use for a mysql space. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted September 17, 2008 Share Posted September 17, 2008 Well, your regex is malformed, which would do it. Try $fixedlink = preg_replace('%[\s]+%', '_', $mustfixlink); Quote Link to comment Share on other sites More sharing options...
Ziph Posted September 17, 2008 Author Share Posted September 17, 2008 hmz does not work still getting the name returned with spaces Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted September 17, 2008 Share Posted September 17, 2008 It worked for me.. try stripping it down. echo preg_replace('%[\s]+%', '_', 'test test test'); if that works (it should) work your way back to how it should be. Quote Link to comment Share on other sites More sharing options...
Ziph Posted September 17, 2008 Author Share Posted September 17, 2008 test test test this is what i get returned shouldnt it be test_test_test or something ? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted September 17, 2008 Share Posted September 17, 2008 correct, and that is what I get. "test_test_test". What version of php are you using? It would have to be old to not have regex enabled, and still somehow manage to run, but... Quote Link to comment Share on other sites More sharing options...
Ziph Posted September 17, 2008 Author Share Posted September 17, 2008 hehe im pretty sure im running php5 If I make a new php file with just <?php $str = 'foo o'; $str = preg_replace('/\s\s+/', ' ', $str); // This will be 'foo o' now echo $str; ?> this one works but when i use '/\s\s+/' this code in my php script it does not =\ like it did iin this script really weird. Quote Link to comment 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.