Hey, has anyone on devnet worked with HTML Purifier before? I was wondering if there was a way to convert all newline characters (\n) to break and paragraph tags (<br> and <p>)? I know there is a directive called AutoParagraph that will allow me to convert all double newlines to paragraph elements. But what I'm looking to do is convert all single newlines to break elements along with the AutoParagraph directive functionality.
Is there a way to do this with HTMLPurifier or would I have to do it with str_replace?
Thanks for reading. All help is appreciated.
HTML Purifier newlines to <br/> elements
Moderator: General Moderators
Re: HTML Purifier newlines to <br/> elements
May be this will help
nl2br (php function) -- converts \n to <br> ..
<p> i don't have an idea ..
nl2br (php function) -- converts \n to <br> ..
<p> i don't have an idea ..
Re: HTML Purifier newlines to <br/> elements
Hmm... Forgot about that function. Maybe this is all I need though.nmreddy wrote:May be this will help
nl2br (php function) -- converts \n to <br> ..
<p> i don't have an idea ..
Thanks!
Re: HTML Purifier newlines to <br/> elements
Actually I don't want to convert newlines that are in html like:
I don't want to place <br/> tags within the p element.
Is there a way to check if there is any HTML in the body before I use nl2br?
Code: Select all
<p>
hello world
</p>Code: Select all
<p><br/>hello world<br/></p>
Last edited by Benjamin on Tue May 19, 2009 2:27 pm, edited 1 time in total.
Reason: Changed code type from text to html.
Reason: Changed code type from text to html.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: HTML Purifier newlines to <br/> elements
I found:
works. But would using a regular expression be faster then strip_tags?
[EDIT] I had to put the wrap="wrap" attribute into the pre element so that text automatically breaks. Is there a way to do this in css?
Code: Select all
$string = $purifier->purify($string);
if (strlen($string) == strlen(strip_tags($string)))
{
$string = "<pre>$string</pre>";
}
[EDIT] I had to put the wrap="wrap" attribute into the pre element so that text automatically breaks. Is there a way to do this in css?
Last edited by Benjamin on Tue May 19, 2009 2:27 pm, edited 1 time in total.
Reason: Changed code type from text to php.
Reason: Changed code type from text to php.