cgm225 Posted August 6, 2007 Share Posted August 6, 2007 Let's say I have a line of code in a MySQL table as following: This is some text in a database table with a carriage return in the middle of it! Now, if I grab that code and echo it, the text will show up in the browser with no line break, which is fine. HOWEVER, if you look at the page source for that code, there is still the carriage return in the middle of the line. My question is, how can I remove that carriage return from the text in the source code. Sincerely, cgm225 Link to comment https://forums.phpfreaks.com/topic/63632-solved-how-to-remove-replace-carriage-returns-in-output-code/ Share on other sites More sharing options...
AndyB Posted August 6, 2007 Share Posted August 6, 2007 Seems pointless if it's only when viewing source, but what you want to remove is the string is "r\n\" BEFORE you send the string to the browser. Link to comment https://forums.phpfreaks.com/topic/63632-solved-how-to-remove-replace-carriage-returns-in-output-code/#findComment-317075 Share on other sites More sharing options...
cgm225 Posted August 6, 2007 Author Share Posted August 6, 2007 so does the following look ok? str_replace("r\n\"," ", $string); or is it str_replace("\r\n"," ", $string); Link to comment https://forums.phpfreaks.com/topic/63632-solved-how-to-remove-replace-carriage-returns-in-output-code/#findComment-317083 Share on other sites More sharing options...
cgm225 Posted August 7, 2007 Author Share Posted August 7, 2007 neither of the above seem to work.. any ideas? Link to comment https://forums.phpfreaks.com/topic/63632-solved-how-to-remove-replace-carriage-returns-in-output-code/#findComment-317092 Share on other sites More sharing options...
teng84 Posted August 7, 2007 Share Posted August 7, 2007 can we see some of that codes Link to comment https://forums.phpfreaks.com/topic/63632-solved-how-to-remove-replace-carriage-returns-in-output-code/#findComment-317106 Share on other sites More sharing options...
cgm225 Posted August 7, 2007 Author Share Posted August 7, 2007 db_connect(); $query = "SELECT * FROM notes WHERE title = '$title'"; $result = mysql_fetch_array(mysql_query($query)); if (!$result['title']) {} else { $note = $result['note']; $noteID = $result['noteID']; $date = $result['date']; $time = $result['time']; $note_modified = str_replace("\r\n"," ", $note); $pubdate = date("D, d M Y H:i:s", $time) . " GMT"; $item = "\t<item>\n\t\t<title>Notes:: $title</title>\n\t\t<link>http://www.kilbad.com/notes/$noteID</link>\n\t\t<guid>http://www.kilbad.com/notes/$noteID</guid>\n\t\t<pubDate>$pubdate</pubDate>\n\t\t<description>$note_modified</description>\n\t</item>\n\n"; $handle = fopen($rss_file, 'a'); fwrite($handle, $item); fclose($handle); } mysql_close(); I just want all of the text from the note to be in one continuous line in the outputted source code.. thanks cgm225 Link to comment https://forums.phpfreaks.com/topic/63632-solved-how-to-remove-replace-carriage-returns-in-output-code/#findComment-317109 Share on other sites More sharing options...
teng84 Posted August 7, 2007 Share Posted August 7, 2007 i feel stupid i tried so many thing even array but the ansewr is only echo str_replace("\n"," ", $string); Link to comment https://forums.phpfreaks.com/topic/63632-solved-how-to-remove-replace-carriage-returns-in-output-code/#findComment-317121 Share on other sites More sharing options...
wildteen88 Posted August 7, 2007 Share Posted August 7, 2007 Best of using an array of newline chars and removing them: $note_modified = str_replace(array("\r\n", "\r", "\n"), "", $note); Link to comment https://forums.phpfreaks.com/topic/63632-solved-how-to-remove-replace-carriage-returns-in-output-code/#findComment-317124 Share on other sites More sharing options...
cgm225 Posted August 7, 2007 Author Share Posted August 7, 2007 @wildteen88 - That is the perfect solution! Thank you so much! @teng84 - Thank you for getting the ball rolling! sincerely, cgm225 Link to comment https://forums.phpfreaks.com/topic/63632-solved-how-to-remove-replace-carriage-returns-in-output-code/#findComment-317133 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.