Ziph Posted September 23, 2008 Share Posted September 23, 2008 For some reason it wont add _ for where the spaces are this is the outcome of this code (Ziph) () test test test = fixedlink http://www.gosuhosting.com/upload/Ziph/0028 shakaalxZ ZiphP.rep = mustfixlink <?php // Start a session session_start(); // Sends the user to the login-page if not logged in if(!session_is_registered('member_ID')) : header('Location: ../login/login.html?msg=requires_login'); endif; // DB connect ifno include '../mysql/db.php'; // functions include '../mysql/functions.php'; $username = user_info('username'); echo "($username) "; echo "($filename) "; $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('[%[\s]+%]', '_', 'test test test'); echo "$fixedlink = fixedlink"; echo "$mustfixlink = mustfixlink"; ?> test test test is ofcourse in the final version to be replaced with $mustfixlink but the test test test is to test it hehe i also tried to rename the file also didnt work. this preg_replace code does work with other people so i dont know what im doing wrong. Link to comment https://forums.phpfreaks.com/topic/125520-link-with-spaces-wont-be-renamed-to-without-spaces/ Share on other sites More sharing options...
discomatt Posted September 23, 2008 Share Posted September 23, 2008 Why not just use $fixedlink = str_replace(' ', '_', 'test test test'); Link to comment https://forums.phpfreaks.com/topic/125520-link-with-spaces-wont-be-renamed-to-without-spaces/#findComment-648996 Share on other sites More sharing options...
Ziph Posted September 23, 2008 Author Share Posted September 23, 2008 haha tnx allot Btw because im a noob at php only started using php and sql this week ^^. can you explain what is the diffrence between str_replace and preg_replace ? Link to comment https://forums.phpfreaks.com/topic/125520-link-with-spaces-wont-be-renamed-to-without-spaces/#findComment-648999 Share on other sites More sharing options...
discomatt Posted September 23, 2008 Share Posted September 23, 2008 preg_replace uses the Regular Expression (google for more information) engine, while str_replace uses simple string matching. str_replace is a lot faster than preg_replace, but nowhere near as powerful. Link to comment https://forums.phpfreaks.com/topic/125520-link-with-spaces-wont-be-renamed-to-without-spaces/#findComment-649048 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.