Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/07/2009, 21:39
Avatar de Italico76
Italico76
 
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 17 años
Puntos: 292
Exclamación Excluir tags con expresiones regulares

Hola amigos, no me funciona el agregado de elementos a un arreglo......asi de tonto como suena! no le encuentro la falla.

A ver si me dicen donde esta! gracias!!!!!

Código PHP:
<?php
$str 
"Me llamo <i>Italico</i> y quisiera terminar este algoritmo en <b>php</b><p/>";

Function 
no_tags($str){  
  
// pre-condicion: la cadena debe empezar con algo distinto a un tag (<)

  
preg_match_all('@(<[/]?[a-z]{1,}[^>]{0,}[/]?[\w]{0,}?>)@is'$str$matches);
  
$full_tags $matches[0];
   
  
$full_tags array_reverse($full_tags); // tengo que sacar del principio
  
$cant count($full_tags);
 

  
$ini 0
  for (
$i=1;$i<=$cant+1;$i++){
    
$ti array_pop ($full_tags);
  
    
$fin  strpos($str$ti,$ini);  
    if (
$fin==NULL$fin=strlen($str);
    
    
$dif  = ($fin-$ini);
  
   
    
$inserto substr ($str,$ini,$dif);  
    
$no_tag[] = $inserto;       
    
//echo "($ini; $fin) ->$inserto <br/>";  
    
$ini $fin +strlen ($ti);  
  }  

  return (array(
$matches[0],$no_tag));
}  



if ((
strlen($str)>0) and ($str[0]=='<')){
  
$str ' '.$str// parche para saber que comienza con algo distinto de un tag y evitar problemas con el offset (?)
  
$quitar_espacio=TRUE;  
}  

list (
$tag,$notag) = no_tags($str);

$cant count ($notag);
for (
$i=0;$i<$cant;$i++){
  
$a $notag[$i];      //  puedo hacerle lo que quiera....
  
$b $tag[$i];
  
$html $html.$a.$b;  // vuelvo a unir las partes
}
  
//$html = $html.$notag[$i+1];

if ($quitar_espacio){
  
$html =substr ($html,1,strlen($html)-1); // elimino espacio agregado por el tema del offset
}     

echo 
$html;
?>
EDIT: actualizado
__________________
Salu2!

Última edición por Italico76; 15/07/2009 a las 22:02