Jump to content

Hello Guys


nepzap2

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.