function html to text

October 18, 2008

function htmltotext($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);

$html = preg_replace(‘~ +~s’,’ ‘,$html);
$html = preg_replace(‘~^\s+~m’,”,$html);
$html = preg_replace(‘~\s+$~m’,”,$html);

$html = preg_replace(‘~\n+~s’,”\n”,$html);
return $html;
}

Entry Filed under: Internet, Php. Tags: , , , , , , , , , , , , .


Archives

Other

Categories

 

October 2008
M T W T F S S
« Sep   Feb »
 12345
6789101112
13141516171819
20212223242526
2728293031  

Tags

.net 1.1 .net 2.0 .net 3.0 ADO.NET all-net-news alltechnews bsod c# c-sharp controls DataSet datasource dba dba-tool entity-framework Framework internet-land internet-life java-script jsf mozilla-foundation msbuild online-tools Page Layout php-development php-programming php5 plug-ins query script-land sql-add-on sql-backup-and-restore sql-data-storage sql-datetime sql-query sql-tips-and-tricks sqlauthority-news status-updates t-sql tech-land tech-review Visual Studio 2008 Web Browser Windows Server xquery