nepzap2 Posted February 27, 2008 Share Posted February 27, 2008 once again I'm here asking questions. I managed to set up a simple database with MySQL and now I'm retrieving the MySQL data and placeing it in a PHP page. I only have one problem... I can't for the life of me figure out how to have PHP interpret whitespace in my database's text area as a line break. In the code below you will see the following Print "<p>". $info['paragraph'] . "</p>"; that's where I want the line breaks to happen. Here is my code <?php // Connects to your Database mysql_connect("localhost", "", "") or die(mysql_error()); mysql_select_db("BTI") or die(mysql_error()); // Collects data from "test" table $data = mysql_query("SELECT * FROM pagebegin") or die(mysql_error()); // Print out the contents of the entry while($info = mysql_fetch_array( $data )) { Print "<h1>" . $info['title'] . "</h1>"; Print "<h2>". $info['subTitle'] . "</h2>"; Print "<p>". $info['paragraph'] . "</p>"; } ?> Thanks for any help. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 27, 2008 Share Posted February 27, 2008 Check out the nl2br() function: http://us.php.net/nl2br print "<p>". nl2br($info['paragraph']) . "</p>"; Your other option is to surround it with PRE tags: print "<p><pre>". $info['paragraph'] . "</pre></p>"; Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 27, 2008 Share Posted February 27, 2008 there is lots of kinds of "whitespace" as you define it i.e the spacing between letters in " W H IT E S P A C E" could be defined as white space or White Space etc. nl2br finds the item \r\n or \r or \n and replaces it with the html tag <br />. nl2br will work for html output, however make sure you know that it won't replace the white space in my first example, it will still output as it is listed, but my second will return "White<Br /><br />Space"; in replace of it being stored as "White\r\n\r\nSpace"; Also mysql Varchars do not keep return breaks usually only text/blobs do Quote Link to comment Share on other sites More sharing options...
nepzap2 Posted February 27, 2008 Author Share Posted February 27, 2008 You guys rock... Thank you so much for the help. Quote Link to comment 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.