visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: checking the contents of files


By: roe1and Great Britain  Date: 08/11/2007 12:33:17  English  Points: 20 Status: Answered
Quality : Excellent
can i use php to check if the files in a folder contain a certain bit of information. i have a directory with subdirectories that contains thousands of xml files. is there(or by now i should say how) a way to run through all of them and see if they contain the tag <APS_content>?
By: VGR Date: 08/11/2007 19:42:43 English  Type : Answer
raté ;-)

there's no "fast & clean" way of doing this.

-fast but dirty : exec() or system() a shell command "grep", get results, parse, and voila
-not fast but clean : read them all using ob_*()+file() or readfile() - I never remember which one outputs the file contents and which one does not - so that all the contents are contained in a big string ; then use strpos() to locate APS_content ; then loop
By: roe1and Date: 09/11/2007 11:02:38 English  Type : Comment
again. had to abandon this. i've read that perl is not that different to php. wish me good luck again
By: VGR Date: 09/11/2007 21:46:04 English  Type : Comment
personally I would stupidly do it like this :

// accès à l'access_log pour (IPaddr,date) $locExtraitlog=''; $lignes=array(); $locannee=substr($locDate,0,4); $locmois=NumToStr3(substr($locDate,5,2)); $locjour=substr($locDate,8,2); $locheure=substr($locDate,11,8); //test echo " exec : C:\grep \"$locIP - - \[$locjour/$locmois/$locannee:$locheure\" \"$accesslog\""; // $locExtraitlog=exec("C:\grep \"$locIP - - \[$locjour/$locmois/$locannee:$locheure\" \"$accesslog\"",$lignes); // le mieux possible en non-root (-f) //test echo " bloc trouvé )".htmlspecialchars($locExtraitlog)."(";


that's very old coding standard but it works. It greps the Apache access.log for a specific IP address and date_time
By: roe1and Date: 10/11/2007 11:36:43 English  Type : Comment
i came accross grep yesterday for the first time. very handy. i've started teaching my wife php too!

Do register to be able to answer

EContact
browser fav
page generated in 107.481960 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page