Jump to content

How To Autodetect Paragraph Breaks


garethppls

Recommended Posts

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);
?>
Link to comment
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.
Link to comment
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
Link to comment
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 :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.