Languages :: PHP :: checking the contents of files |
|||
| By: roe1and |
Date: 08/11/2007 12:33:17 |
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 | 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 | 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 | 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 | 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 |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








