Búsqueda


Categorías

C# [15]
PHP [6]
Zend [1]
FileMaker [1]
.NET [6]
CVS [3]
General [9]
Javascript [2]
Paypal [1]
.NET Compact Framework [3]
C++ [1]
mysql [4]
Linux [1]

Últimos post

Dónde guardar los archivos de configuración en ClickOnce
phpinfo: Valores en error_reporting
Notes about Zend Server and Zend Studio setup
What's new in C# 4
Resolving a 'sticky tag is not a branch' error
Resumen del CodeCamp
CodeCamp Tarragona 2009
Acerca de la calidad del código
ClickOnce en Linux
Programando en PHP (y con CVS) en Visual Studio 2008

Sindicación

RSS 0.90
RSS 1.0
RSS 2.0
Atom 0.3

Convert HTML into text

ctg | 16 Agosto, 2006 15:01

I put this code here (for future review). It’s a simple code for convert HTML into text (or remove HTML tags) 

<?php
// $document should contain an HTML document.
// This will remove HTML tags, javascript sections
// and white space. It will also convert some
// common HTML entities to their text equivalent.
$search = array ("'<script[^>]*?>.*?</script>'si",
// Strip out javascript "'<[/!]*?[^<>]*?>'si", // Strip out HTML tags
"'([rn])[s]+'", // Strip out white space
"'&(quot|#34);'i",// Replace HTML entities
"'&(amp|#38);'i", "'&(lt|#60);'i", "'&(gt|#62);'i", "'&(nbsp|#160);'i", "'&(iexcl|#161);'i", "'&(cent|#162);'i", "'&(pound|#163);'i", "'&(copy|#169);'i", "'&#(d+);'e"); // evaluate as php
$replace = array ("", "", "\1", "\"", "&", "<", ">", " ", chr(161), chr(162), chr(163), chr(169), "chr(\1)");
$text = preg_replace($search, $replace, $document);
?>
 

Posted in PHP . Comentario: (0). Retroenlaces:(0). Enlace
«Next post | Previous post»

Comentarios

Deja un comentario
















Primer mes del año: