Re: buscar dentro de archivo

From: Date: Fri, 12 Dec 2003 21:42:26 +0000
Subject: Re: buscar dentro de archivo
References: 1 2 3  Groups: php.general.es 
Request: Send a blank email to general-es+get-43610@lists.php.net to get a copy of this message
Este código lo he verificado y funciona. Copy & Paste, y lo ejecutas. $filename : Nombre del fichero. $buscar: Cadena que quieres buscar. $n: Longuitud que quieres capturar despues de se encuentre la cadena. $resultado: Array que contiene cada una de las capturas. No assignes el nombre del fichero, antes pruebalo con la cadena que viene por defecto. Una vez que veas que funciona correctamente, cambia el nombre del fichero por el que tu quieras. Un Saludo. <html> <head> <body> <?php $filename="text.txt"; if ($fd = @fopen($filename, 'r')) { $f = fread ($fd, filesize ($filename)); } else $f="NO:XML Web services are the fundamental building blocks in the move to distributed computing on the Internet. Open standards and the focus on communication and collaboration among people and applications have created an environment where XML Web services are becoming the platform for application integration. Applications are constructed using multiple XML Web services from various sources that work together regardless of where they reside or how they were implemented."; $buscar="XML"; $n=40; print($f); while ($f=strstr($f,$buscar)) { $resultado[]=substr($f,0,$n+strlen($buscar)); $f =substr($f,strlen($buscar)); } print("<br /><br /> Resultado:"); var_dump($resultado); ?> </body> </html>

« previous php.general.es (#43610) next »