Hi all,

I am looking to understand Html entities & html special chars in more details.

I have a form and text area that users complete, the databse updates correctly and displays the information.

The problem im facing is this:
When the database displays the data, its display incorrectly.

For example:
If the user enters
Line 1
Line 2
Line 3

The data is stored correctly in the database, including the line brakes.
But when the data is displayed on the page, it is displaying as
Line 1 Line 2 Line 3 ? How can I display the data from the database correctly.

Here is my form

<form style="width:100%;" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<div><div class="p">
    <textarea name="sabout" cols="35" rows="5" class="ta" id="sabout" style='width:99.9%;'/><?php echo htmlspecialchars($_POST['sabout']); ?></textarea></form>

I have the following variable to display the data from the database -

$sabout = htmlspecialchars($sabout);

Displaying the variable in my page

<?php if($sabout){echo $sabout; }?>

any help would be appreciated, thanks

$sabout=nl2br($sabout);

Give that a shot. When data is entered into a DB hard returns (hitting the Enter button) will be converted to \n (newline) \r (return) or a combination of both. nl2br will take newlines and returns and convert them to the html linebreak &lt;br /&gt;

commented: Useful post +7

@weekendrockstar - You surely do rock, that works a treat, thank you :)

just one more question if you dont mind. . . I am trying to add the above into a different part of my code -

the variables are

".$numrows[description]."

How can I add your code to the above ?

Member Avatar for diafol
".nl2br($numrows['description'])."

sorry for jumping in

@ardav - not a problem about jumping in, cheers for the input, its works a treat :)

Mark this thread as solved if your problem solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.