|
-
Jul 13th, 2005, 01:28 PM
#1
Thread Starter
Lively Member
[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.
Hello friend,
how are you
The person will see this message like this.
I want to keep the spaces
Last edited by Shadows; Jul 13th, 2005 at 06:48 PM.
-
Jul 13th, 2005, 04:31 PM
#2
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);
-
Jul 13th, 2005, 06:47 PM
#3
Thread Starter
Lively Member
Re: upon $_POST keep spaces and formatting
 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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|