0

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

4
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by karthik_ppts
1
$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;

Votes + Comments
Useful post
0

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 ?

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.