Mundo Posted October 19, 2009 Share Posted October 19, 2009 I have data in my MySQL such as: Blah blah Blah blah etc but when i echo it out, there is no formatting left it comes out as: Blah blah Blah blah etc is there an easy way to stop this? Link to comment https://forums.phpfreaks.com/topic/178284-echo-ing-mysql-content-and-keep-formatting/ Share on other sites More sharing options...
Daniel0 Posted October 19, 2009 Share Posted October 19, 2009 What do you mean? If you output things, it'll be output verbatim. If you output things to a browser with an text/html MIME type it will ignore consecutive whitespace, however (check the source). You can use nl2br to convert line breaks (ASCII code 10) to (X)HTML line breaks. You can also use CSS rules to preserve whitespace. Link to comment https://forums.phpfreaks.com/topic/178284-echo-ing-mysql-content-and-keep-formatting/#findComment-940060 Share on other sites More sharing options...
Mundo Posted October 19, 2009 Author Share Posted October 19, 2009 Well basically the data in the database has linebreaks but when i output it the linebreaks disappear... I want them back without having to insert HTML into the database. As you can see in my screenshot... I want my linebreaks to back to make it more readable. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/178284-echo-ing-mysql-content-and-keep-formatting/#findComment-940064 Share on other sites More sharing options...
Mundo Posted October 19, 2009 Author Share Posted October 19, 2009 (ignore the narrow layout etc, it's designed for iPhone) Link to comment https://forums.phpfreaks.com/topic/178284-echo-ing-mysql-content-and-keep-formatting/#findComment-940065 Share on other sites More sharing options...
Mundo Posted October 20, 2009 Author Share Posted October 20, 2009 There must be a simple way to do this? Link to comment https://forums.phpfreaks.com/topic/178284-echo-ing-mysql-content-and-keep-formatting/#findComment-940530 Share on other sites More sharing options...
redarrow Posted October 20, 2009 Share Posted October 20, 2009 Can i see the format you already done please. you been advised ill hold your hand? Link to comment https://forums.phpfreaks.com/topic/178284-echo-ing-mysql-content-and-keep-formatting/#findComment-940535 Share on other sites More sharing options...
Mundo Posted October 20, 2009 Author Share Posted October 20, 2009 $query = mysql_query("SELECT * FROM recipes WHERE id = '$_GET[recipeid]'"); $row = mysql_fetch_assoc($query); $method = $row['method']; $method = str_replace('<br />', "\n", $method); I've currently got this, but this won't add my line breaks back in either. What do you mean, see the format i've already done? Link to comment https://forums.phpfreaks.com/topic/178284-echo-ing-mysql-content-and-keep-formatting/#findComment-940538 Share on other sites More sharing options...
Daniel0 Posted October 20, 2009 Share Posted October 20, 2009 You can use nl2br to convert line breaks (ASCII code 10) to (X)HTML line breaks. Link to comment https://forums.phpfreaks.com/topic/178284-echo-ing-mysql-content-and-keep-formatting/#findComment-940541 Share on other sites More sharing options...
redarrow Posted October 20, 2009 Share Posted October 20, 2009 Dan was trying to teach you, new line to brake, Look at the examples in the below link your understand. http://uk2.php.net/nl2br Siide note. when you enter information in the database, as a brake <br> it's referenced as a special character, to tell the database it a brake <br>, you Paul them brakes out using nl2br() function. database example with $row $text=nltbr($row['text']); echo $text walla. Link to comment https://forums.phpfreaks.com/topic/178284-echo-ing-mysql-content-and-keep-formatting/#findComment-940542 Share on other sites More sharing options...
Daniel0 Posted October 20, 2009 Share Posted October 20, 2009 ... what? That post doesn't make sense. Link to comment https://forums.phpfreaks.com/topic/178284-echo-ing-mysql-content-and-keep-formatting/#findComment-940548 Share on other sites More sharing options...
Mundo Posted October 20, 2009 Author Share Posted October 20, 2009 Ah sorry, was as simple as nl2br($row['method']); Sorry I must have misread your post before. Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/178284-echo-ing-mysql-content-and-keep-formatting/#findComment-940549 Share on other sites More sharing options...
redarrow Posted October 20, 2009 Share Posted October 20, 2009 dan i tried again lol. Dan was trying to teach you, new line to brake, Look at the examples in the below link your understand. http://uk2.php.net/nl2br Side note. when you enter information in the database, as a brake <br> it's referenced as a special character, to tell the database it a brake <br>, you Paul them brakes out using nl2br() function. database example with $row $text=nltbr($row['text']); echo $text walla. Link to comment https://forums.phpfreaks.com/topic/178284-echo-ing-mysql-content-and-keep-formatting/#findComment-940551 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.