SirChick Posted November 3, 2007 Share Posted November 3, 2007 Say i have a variable with this as its input: G f h s hhss s f when this is inputted into the database it goes in completely blank.. so was wondering if theres a way to remove the lines to make just spaces? so it would become G f h s hhss s f is this possible? Quote Link to comment https://forums.phpfreaks.com/topic/75864-solved-remove-break-lines/ Share on other sites More sharing options...
kratsg Posted November 3, 2007 Share Posted November 3, 2007 //non-escaped version str_replace('\n',''$str); //escaped version str_replace('\\n',''$str); Those should do it. However, I forget if PHP reads \n as a new line inside a function or not, so try both ways, see which produces the output correctly. Quote Link to comment https://forums.phpfreaks.com/topic/75864-solved-remove-break-lines/#findComment-383982 Share on other sites More sharing options...
wildteen88 Posted November 3, 2007 Share Posted November 3, 2007 //non-escaped version str_replace('\n',''$str); //escaped version str_replace('\\n',''$str); Those should do it. However, I forget if PHP reads \n as a new line inside a function or not, so try both ways, see which produces the output correctly. That code wont work. You must use double quotes when using whitespace characters within strings: $str = 'G f h s hhss s f'; $str = str_replace(array("\r\n", "\r", "\n"), ' ', $str); echo $str; // outputs: G f h s hhss s f Quote Link to comment https://forums.phpfreaks.com/topic/75864-solved-remove-break-lines/#findComment-384151 Share on other sites More sharing options...
SirChick Posted November 3, 2007 Author Share Posted November 3, 2007 thanks wildteen just one other quick question say i have a number 123,000 and i want it to be integer so there is no , do i do : $str = '124,0002; $str = str_replace(array(","), ' ', $str); echo $str; ? Quote Link to comment https://forums.phpfreaks.com/topic/75864-solved-remove-break-lines/#findComment-384222 Share on other sites More sharing options...
Orio Posted November 3, 2007 Share Posted November 3, 2007 In this case you don't need the array, since you only want to convert one thing into something else, not multiple things. So: <?php $str = "124,0002"; $str = str_replace(",", "", $str); echo $str; ?> Orio. Quote Link to comment https://forums.phpfreaks.com/topic/75864-solved-remove-break-lines/#findComment-384242 Share on other sites More sharing options...
rajivgonsalves Posted November 3, 2007 Share Posted November 3, 2007 this should be the code or it might take out comma from a string say "hi there, how are you doing" <?php $str = '124,0002'; $str = preg_replace("/(\d+)\,(\d+)/", "$1$2", $str); echo $str; ?> Quote Link to comment https://forums.phpfreaks.com/topic/75864-solved-remove-break-lines/#findComment-384244 Share on other sites More sharing options...
SirChick Posted November 3, 2007 Author Share Posted November 3, 2007 thanks guys it works a treat Quote Link to comment https://forums.phpfreaks.com/topic/75864-solved-remove-break-lines/#findComment-384274 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.