To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Upgrading PHP

Upgrading PHP Issues concerning PHP version upgrades and future releases

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-28-2004, 06:03 PM   #1
yelvington
Senior Member
 
Join Date: Dec 2000
Location: USA
Posts: 1,012
Paragraph-style input with PHP5 and tidy

I see a lot of questions posted about how to handle textarea input -- often from people who forget the rules of HTML and don't understand why line enders disappear.

The following code takes input, converts line enders to paragraph tags, and runs the result through tidy to clean up any bad HTML. The result is a properly formed HTML fragment with paragraphs handled properly.

Since PHP5 includes tidy functions, I was able to cut a fairly long piece of code that called an external tidy binary down to just a few lines.

PHP Code:
function validate($input)
        {
        if (
get_magic_quotes_gpc()) $input = stripslashes($input);
        
$input = strip_tags($input,'<blockquote><ul><li><a><b><i><img><br><u><p><em>');
        
$input = str_replace("\n", '<p>', $input);
        
$tidycfg = array('show-body-only' => TRUE, 'enclose-text' => TRUE);
        
$input = tidy_repair_string($input, $tidycfg);
        return
addslashes($input);
        }
yelvington is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 10:49 AM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.