Normally when I make a site I use an editor I made with the help of Demonslay that has buttons to do the html fucctions like <p></p> extra. But I have been reading on php.net if there is a way to do away with this editor and have it so if that a person presses enter it adds a new line thing in the code and if shit + enter a new paragraph.
After a heap of reading (so many commands on php) I could not see anything obvious that would get this.
Anyone have any ideas how I could make this happen?
Ta Muchly.
New line and paragraphs.
Started by _*Creative Insanity_*, Sep 04 2007 01:04 PM
5 replies to this topic
#1 _*Creative Insanity_*
Posted 04 September 2007 - 01:04 PM
#3 _*Creative Insanity_*
Posted 05 September 2007 - 04:48 AM
Yeah sounds the ticket.
I like the looks of this one.
But how it all works in a form is a little over the head. Been having a play and nothing worked. I get there I guess. hehe
I like the looks of this one.
<?php
function nls2p($str)
{
return str_replace('<p></p>', '', '<p>'
. preg_replace('#([\r\n]\s*?[\r\n]){2,}#', '</p>$0<p>', $str)
. '</p>');
}
?>
But how it all works in a form is a little over the head. Been having a play and nothing worked. I get there I guess. hehe
Edited by Creative Insanity, 05 September 2007 - 04:49 AM.
#4 _*Creative Insanity_*
Posted 05 September 2007 - 06:43 PM
Ok how do these work with a textarea? I replaced the $str with the area ID and nup.. I don't understand how to get these to look at the textarea.
Do I need to place an echo somewhere and if so echo what?
Ta muschly
Do I need to place an echo somewhere and if so echo what?
Ta muschly
#5
Posted 05 September 2007 - 09:43 PM
What?
When you are using nl2br(), this is when you are processing the code. If a user presses enter inside of a textarea, it already adds a newline, and visually, they are on another line, or another paragraph. Same way that you are using the editor when you are posting a reply. When I submit this with enter spaces, they are newline characters, and the forum processes them into HTML breaks (<br />), thus keeping the same intended outline of paragraphs.
Also note that you should actually use nl2br() when you are outputting the code, and not storing it like that in the database. This can be fatal, when you goto use something like htmlspecialchars() before outputting... so use nl2br() as the last cleaning function.
When you are using nl2br(), this is when you are processing the code. If a user presses enter inside of a textarea, it already adds a newline, and visually, they are on another line, or another paragraph. Same way that you are using the editor when you are posting a reply. When I submit this with enter spaces, they are newline characters, and the forum processes them into HTML breaks (<br />), thus keeping the same intended outline of paragraphs.
Also note that you should actually use nl2br() when you are outputting the code, and not storing it like that in the database. This can be fatal, when you goto use something like htmlspecialchars() before outputting... so use nl2br() as the last cleaning function.
Edited by Demonslay, 05 September 2007 - 09:44 PM.
#6 _*Creative Insanity_*
Posted 05 September 2007 - 10:02 PM
Ahh so now I get it.. so you enter the text into the database with the blank lines, and when VIEWING is where you execute the nl2br. This the correct understanding?
If not will just use my buttons you help me with hehe.
By gosh I got it!
Awesome
the echo
Thanks again demonslay awesome!
If not will just use my buttons you help me with hehe.
By gosh I got it!
Awesome
the echo
<?php echo nl2br(nls2p($row_RSscript['txt'])); ?>the result
Quote
<p>This is my line break test<br />
now this shoudl be a new para</p><br />
<br />
<p>no idea what this is</p></body>
</html>
now this shoudl be a new para</p><br />
<br />
<p>no idea what this is</p></body>
</html>
Edited by Creative Insanity, 05 September 2007 - 10:15 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
