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. Link to comment https://forums.phpfreaks.com/topic/124698-replacing-html-spaces/ 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); Link to comment https://forums.phpfreaks.com/topic/124698-replacing-html-spaces/#findComment-644088 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 Link to comment https://forums.phpfreaks.com/topic/124698-replacing-html-spaces/#findComment-644094 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. Link to comment https://forums.phpfreaks.com/topic/124698-replacing-html-spaces/#findComment-644099 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 ? Link to comment https://forums.phpfreaks.com/topic/124698-replacing-html-spaces/#findComment-644120 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... Link to comment https://forums.phpfreaks.com/topic/124698-replacing-html-spaces/#findComment-644121 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. Link to comment https://forums.phpfreaks.com/topic/124698-replacing-html-spaces/#findComment-644131 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.