Foros del Web » Programando para Internet » PHP »

[Ayuda] Filtrar código html

Estas en el tema de [Ayuda] Filtrar código html en el foro de PHP en Foros del Web. functions.php Código PHP:   <?php function  parse_links ( $str ,  $len = 25 ,  $mid = '...' ){ $left  =  ceil ( 0.6666  *  $len ...
  #1 (permalink)  
Antiguo 08/09/2010, 17:17
 
Fecha de Ingreso: septiembre-2009
Mensajes: 230
Antigüedad: 17 años
Puntos: 2
[Ayuda] Filtrar código html

functions.php
Código PHP:
 <?php
function parse_links($str, $len=25, $mid='...'){
$left = ceil(0.6666 * $len);
$right = $len - $left;
preg_match_all('/(?<!=|\]|\/)((https?|ftps?|irc):\/\/|' . '(www([0-9]{1,3})?|ftp)\.)([0-9a-z-]{1,25}' . '[0-9a-z]{1}\.)([^\s&\[\{\}\]]+)/ims', $str, $matches);
foreach(
$matches[0] as $key=>$value){
$temp = $value;
if(
strlen($value) > ($len + strlen($mid) + 2)){
$value = substr($value, 0, $left) . $mid . substr($value,(-1 * $right));
}
$temp = !preg_match('/:\/\//', $temp) ? (substr($temp, 0, 3) === 'ftp' ? 'ftp://' . $temp : 'http://' . $temp) : $temp;
$temp = $temp === $matches[0][$key] && $value === $matches[0][$key] ? '' : '=' . $temp;
$str = str_replace($matches[0][$key],'[url' . $temp . ']' . $value . '[/url]', $str);
}
$str = preg_replace('/\[url=(?!http|ftp|irc)/ims', '[url=http://', $str);
$str = preg_replace('/\[url\](.+?)\[\/url\]/ims','<a href="$1" title="$1">$1</a>',$str);
$str = preg_replace('/\[url=(.+?)\](.+?)\[\/url\]/ims', '<a href="$1" title="$1">$2</a>', $str);
return 
$str;
}
?>
Lo que yo quisiera, es editar esta función para también filtrar etiquetas html, o, código html en el string. Alguna idea? Gracias de ante mano.
  #2 (permalink)  
Antiguo 08/09/2010, 17:52
Avatar de spider_boy  
Fecha de Ingreso: diciembre-2003
Ubicación: Chile
Mensajes: 1.855
Antigüedad: 22 años, 9 meses
Puntos: 89
Respuesta: [Ayuda] Filtrar código html

¿Tú dices algo como en este foro? ¿[ b], [ color], etc?

http://www.desarrolloweb.com/articulos/2438.php

Incluso PHP tiene una librería BBCode : http://www.php.net/manual/es/book.bbcode.php
__________________
Nunca te olvidaré mi negra hermosa. Te extraño demasiado.
  #3 (permalink)  
Antiguo 08/09/2010, 18:11
 
Fecha de Ingreso: septiembre-2009
Mensajes: 230
Antigüedad: 17 años
Puntos: 2
Respuesta: [Ayuda] Filtrar código html

Cita:
Iniciado por spider_boy Ver Mensaje
¿Tú dices algo como en este foro? ¿[ b], [ color], etc?

http://www.desarrolloweb.com/articulos/2438.php

Incluso PHP tiene una librería BBCode : http://www.php.net/manual/es/book.bbcode.php
Me sirvio perfecto! Muchas gracias!

Etiquetas: filtrar, html
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:26.