Jump to content

Archived

This topic is now archived and is closed to further replies.

garethppls

How To Autodetect Paragraph Breaks

Recommended Posts

I have a form but I want to disable HTML. the problem with this is the form doesn't recognise paragraph breaks. any way of doing this like on this forum.
thanks,

Share this post


Link to post
Share on other sites
is your answer in one of these 3?

<?php
$text = '<p>Test paragraph.</p><!-- Comment --> Other text';
echo strip_tags($text);
echo "\n";

// Allow <p>
echo strip_tags($text, '<p>');
?>

The above example will output:

Test paragraph. Other text
<p>Test paragraph.</p> Other text

<?php
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; // &lt;a href='test'&gt;Test&lt;/a&gt;
?>


<?php
$str = "A 'quote' is <b>bold</b>";

// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);

// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str, ENT_QUOTES);
?>

Share this post


Link to post
Share on other sites
You'll want to lookinto nl2br function ie:
[code]<?php

$str = "this text\nhas line\nbreaks in\n it!";

// convert carriage returns into line breaks (<br />)
echo nl2br($str);

?>[/code]

Also if you want to only allow paragraph tags you can use a function called [a href=\"http://www.php.net/strip-tags\" target=\"_blank\"]strip_tags[/a]. For example:
[code]<?php

$str = "this text<p>is only <b>allowed</b></p>paragraphs!";

// strip all tags from $str but keep < p></p>!
echo strip_tags($str, '<p>');

?>[/code]

Hope that helps.

Share this post


Link to post
Share on other sites
no I want it to detect paragraph breaks in a form without putting <p> in , just like this forum as its a forum script i'm making

Share this post


Link to post
Share on other sites
User eregi or eregi_replace to do something like...

eregi("\n\r", $string);

Share this post


Link to post
Share on other sites
One thing I've noticed is that with <input type="text"> tags in HTML when they are submitted to a database (like MySQL) it will read the carriage returns and store them properly.

Using echo nl2br($string); works fine when outputting what was in the database and putting in the paragraphs properly. Seems to be fine for windows/macs/un*x type plateforms.

*edit ok that is cool, the forum read my input tag and displayed it hehe

Share this post


Link to post
Share on other sites
yep that worked thanks sharkbait. I used nl2br before inserting it to the MYSQL but its all good :)

Share this post


Link to post
Share on other sites
Isn't that what I suggested in my post above? Prehaps I didnt explain it very well.

Share this post


Link to post
Share on other sites
[!--quoteo(post=389422:date=Jun 29 2006, 01:10 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 29 2006, 01:10 PM) [snapback]389422[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Isn't that what I suggested in my post above? Prehaps I didnt explain it very well.
[/quote]


You did, I was just agreeing with what you said :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.