siddscool19 Posted October 18, 2008 Share Posted October 18, 2008 How to replace line like this say $data="My name is Rohan"; Now what I want to get the line in this format $data="My name is - Rohan" That is I want to replace newline character with " - ". How to do it? Link to comment https://forums.phpfreaks.com/topic/128922-need-help/ Share on other sites More sharing options...
Guest Posted October 18, 2008 Share Posted October 18, 2008 You can do: $newdata = str_replace("\n", '-', $data); Note: the double quotes are required when you want to parse special characters. Hopefully that's what you meant. Link to comment https://forums.phpfreaks.com/topic/128922-need-help/#findComment-668417 Share on other sites More sharing options...
siddscool19 Posted October 18, 2008 Author Share Posted October 18, 2008 But when I look in html page source the characters are in separate lines ? And also what encoding does PHP uses while sending data from it Say i builted a form in php file and send data using it it uses different encoding where if i send from a HTML form it uses different encoding Link to comment https://forums.phpfreaks.com/topic/128922-need-help/#findComment-668420 Share on other sites More sharing options...
Guest Posted October 18, 2008 Share Posted October 18, 2008 Oh, that may be because you're probably testing your script on windows, or you're hosting your test server on windows. I forgot which is which, but if i remember correctly: on windows linebreaks are \r\n on linux it's \n on mac it's \r I'm guessing you're on windows, so try doing this instead: $newdata = str_replace("\r\n", '-', $data); Link to comment https://forums.phpfreaks.com/topic/128922-need-help/#findComment-668422 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.