Jump to content

[SOLVED] displaying text problem unwanted break


shadiadiph

Recommended Posts

Hi I in my form I am calling data from the database already stored.

This is probably a simple solution but I have no idea what it is.

 

<tr><td><span id="t_description">DESCRIPTION</span></td></tr>
<tr><td><textarea name="description"><? print $description; ?></textarea></td></tr>

 

the problem is that it is displaying

steel metal ones<br />

plastic ones

 

the <br /> is not supposed to display how can i display this without the <br/> tag?

The data entered by the user did have a line break but not a visible one?

Link to comment
Share on other sites

At some point nl2br() is being called on the input text, and then htmlspecialchars() or htmlentities() is being called on that.  Try this:

 

 

 

<tr><td><span id="t_description">DESCRIPTION</span></td></tr>
<tr><td><textarea name="description"><? print html_entity_decode($description); ?></textarea></td></tr>

Link to comment
Share on other sites

mm that doesn't work yes you are right when the data gets saved it uses nl2br() to make sure the data is formated in the way it was entered by the user just need to know how to unformat that code.?

 

when I save it i am passing the data to be inserted to the database i am using $description =(nl2br($_POST["description"]));

 

Link to comment
Share on other sites

Wow, do not use nl2br to save buddy. You only use that to display data. If you use it to save you come across the problem that it is much harder to reverse that. Which is why you always save data in it's raw format. Not the displayed format.

 

Fix that problem and you will not have this issue later on. Then use nl2br when you need it on displaying the data.

Link to comment
Share on other sites

I took out the  nl2br  when i display the text by calling it from the database the forst time using

$description      = $row["description"];

<tr><td><textarea name="description"><? print $description; ?></textarea></td></tr>

it diplays normally i then saved the page exactly the same and when it reloads to the second page onchange it starts showing the <br /> tags again makes no sense as the coding is he same??

Link to comment
Share on other sites

I don't really understand what you mean.  You just need to make sure that you are saving the description in its raw state, without calling nl2br().  That way, you will always have "\n" in your database and whenever you want to display the formatted text, use nl2br().

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.