Ver Mensaje Individual
  #19 (permalink)  
Antiguo 15/07/2009, 14:33
Avatar de Italico76
Italico76
 
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 17 años
Puntos: 292
Bien.... "puede" que este bien ahora....aca el codigo:

Código PHP:
<?php
$str 
'Me<b></b> llamo <i>Italico</i> y quisiera terminar este algoritmo en <b>php</b><p/><a    href="http://www.mundo.es"  title="cualquier fruta" rel=\'nofollow\'    >Pepes world</a><img src="lalala"/> <a href="www.google.com">Google</a> ja <iMg   SRC="casa.jpg" />la la la' ;

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;  
?>

Cita:
Iniciado por abimaelrc Ver Mensaje
Se fue el monumento para mexico de nuevo jajaja.

Bueno lo unico que te sugiero es que uses la expresion asi

Código PHP:
preg_match_all('@<[^>]*>@i'$str$matches); 
Gracias ABI! si... a GatorV no se le escapa nada pero valoro mucho lo que has hecho

Voy a probar todo.....

GRACIAS A TODOS MIS AMIGOS
__________________
Salu2!

Última edición por Italico76; 15/07/2009 a las 21:59