Foros del Web » Programando para Internet » PHP »

REGEX (palabras completas)

Estas en el tema de REGEX (palabras completas) en el foro de PHP en Foros del Web. Hola Este preg_match está fallando Por qué ????????????? Código PHP: <?PHP $key = "word" ; $data = "testing2.txt<br>The solutions that are currently available usually involve using binaries such as catdoc or antiword.  Good as these products are, they can be complicated to install and configure (sometimes impossible if using a shared hosting account).Heres a simple attempt at a solution using just PHP. I dont pretend that it makes a complete success of extracting the text from all Word documents, but Ive found it very reliable for the vast majority of the several thousand docs Ive used it with. The function returns text from the Word document as a string, with all the formatting removed. Please note that some parts of the Word document (header, footer etc) are not parsed. Y, 6Q" ; if( preg_match ...
  #1 (permalink)  
Antiguo 26/08/2009, 10:51
(Desactivado)
 
Fecha de Ingreso: septiembre-2004
Mensajes: 360
Antigüedad: 19 años, 7 meses
Puntos: 1
REGEX (palabras completas)

Hola
Este preg_match está fallando
Por qué ?????????????

Código PHP:
<?PHP
$key
="word";
$data="testing2.txt<br>The solutions that are currently available usually involve using binaries such as catdoc or antiword.  Good as these products are, they can be complicated to install and configure (sometimes impossible if using a shared hosting account).Heres a simple attempt at a solution using just PHP.
I dont pretend that it makes a complete success of extracting the text from all Word documents, but Ive found it very reliable for the vast majority of the several thousand docs Ive used it with.
The function returns text from the Word document as a string, with all the formatting removed.
Please note that some parts of the Word document (header, footer etc) are not parsed.
Y, 6Q"
;

if(
preg_match("/\b$key\b/i",$data)){
                                        
$hack=strtolower($data);
                                        
$key=strtolower($key);
                                        
$cnt=substr_count($hack,$key);
                                        
$res_tab.="<td>".$cnt."</td>";
                                    }else{
                                        
$res_tab.="<td>0</td>";
                                    }
                                    echo 
$res_tab;
?>
Word (palabra completa) está tres veces en el texto
Sin embargo obtengo siempre 4... a pesar del modificador "b".
Alguien sabe ?
  #2 (permalink)  
Antiguo 26/08/2009, 10:55
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: REGEX (palabras completas)

mmm....

es porque usas substr_count() y por "casualidad" existe una palabra antiword en el texto...

así que el preg_match() no lo estas usando correctamente... y solo lo empleas para verificar palabras, ya que el momento de contarlas... usas la función errónea (substr_count())

revisa esto
Código PHP:
preg_match("/\b$key\b/i",$data,$match);
var_dump(sizeof($match[0]), $match[0]); 
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 26/08/2009, 11:02
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 11 meses
Puntos: 1517
Respuesta: REGEX (palabras completas)

Porque no usas mejor preg_match_all()
Código php:
Ver original
  1. <?php
  2. $key="word";
  3. $data="testing2.txt<br>The solutions that are currently available usually involve using binaries such as catdoc or antiword.  Good as these products are, they can be complicated to install and configure (sometimes impossible if using a shared hosting account).Heres a simple attempt at a solution using just PHP.
  4. I dont pretend that it makes a complete success of extracting the text from all Word documents, but Ive found it very reliable for the vast majority of the several thousand docs Ive used it with.
  5. The function returns text from the Word document as a string, with all the formatting removed.
  6. Please note that some parts of the Word document (header, footer etc) are not parsed.
  7. Y, 6Q";
  8. preg_match_all("/\b".$key."\b/i",$data,$m);
  9. print_r($m[0]);

Te va a traer 3 solamente.
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos
  #4 (permalink)  
Antiguo 26/08/2009, 11:06
(Desactivado)
 
Fecha de Ingreso: septiembre-2004
Mensajes: 360
Antigüedad: 19 años, 7 meses
Puntos: 1
Respuesta: REGEX (palabras completas)

... el que sabe... sabe

Muchísimas gracias a los dos !!!
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 20:04.