[RESOLVED] upon $_POST keep spaces and formatting
Hello, I'm after a little tip. I am making a pm system for my website, the problem is the majority of people on my site wont know html. In the text area when a user spaces out there message (paragraph) with the enter key. I want this to stay the same. When the person gets this message, the space is gone. Any idea's. Like if I send this.
Quote:
Hello friend,
how are you
The person will see this message like this.
Quote:
Hello friend,how are you
I want to keep the spaces :(
Re: upon $_POST keep spaces and formatting
When you output the text use the nl2br() function. This will convert all new lines to HTML line breaks. If you want to preserve spaces, you should use <pre> tags.
PHP Code:
?>
<pre>
<?php echo($text); ?>
</pre>
You can also use the str_replace() function to find all spaces and replace them with a non breaking soace ' ':
PHP Code:
$text = str_replace(' ', '&vbsp;', $text);
Re: upon $_POST keep spaces and formatting
Quote:
Originally Posted by visualAd
When you output the text use the
nl2br() function. This will convert all new lines to HTML line breaks. If you want to preserve spaces, you should use <pre> tags.
PHP Code:
?>
<pre>
<?php echo($text); ?>
</pre>
You can also use the
str_replace() function to find all spaces and replace them with a non breaking soace ' ':
PHP Code:
$text = str_replace(' ', '&vbsp;', $text);
absolutely fantasic, thank you mate, my script works perfectly from your tip, thank you!