Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: Strip HTML to Text Jump to:  
Category: >> PHP Code >> Strip HTML to Text Bookmark and Share

<< lastnext >>

Snippet Name: Strip HTML to Text

Description: Strips tags, tables, etc and returns nice, clean text from HTML source.

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: February 27th, 2009

<?PHP
 
FUNCTION html2text($html){
    $tags = ARRAY (
    0 => '~<h[123][^>]+>~si',
    1 => '~<h[456][^>]+>~si',
    2 => '~<table[^>]+>~si',
    3 => '~<tr[^>]+>~si',
    4 => '~<li[^>]+>~si',
    5 => '~<br[^>]+>~si',
    6 => '~<p[^>]+>~si',
    7 => '~<div[^>]+>~si',
    );
    $html = PREG_REPLACE($tags,"\n",$html);
    $html = PREG_REPLACE('~</t(d|h)>\s*<t(d|h)[^>]+>~si',' - ',$html);
    $html = PREG_REPLACE('~<[^>]+>~s','',$html);
    // reducing spaces
    $html = PREG_REPLACE('~ +~s',' ',$html);
    $html = PREG_REPLACE('~^\s+~m','',$html);
    $html = PREG_REPLACE('~\s+$~m','',$html);
    // reducing newlines
    $html = PREG_REPLACE('~\n+~s',"\n",$html);
    RETURN $html;
}
 
?>


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 66 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?