...

View Full Version : recursively read a dir and all files ( new to php )



whitevamp
02-10-2010, 11:38 PM
I have a php parser script that is working ok for single file parsing, but id like it to parse multipul file from a directory
( dir0/file1 dir0/file2 dir0/dir1/file1 dir0/dir1/file2 etc: ) i have tryed different things but to avale.

here is the code that works for single file parsing.



<?php
include_once('simple_html_dom.php');

$html = file_get_html('1.html');

$e = $html->find('table', 0)->find('pre', 0);
$body = '';
foreach ($e as $element)
$body .= '' . $element->plaintext . '';
$body .= '';
$html = str_get_html($body);
$html->save('result.htm');

?>


here is a pice of code that i have tryed.



<?php
include_once('simple_html_dom.php');

$strDir = ('D:\simplehtmldom\test');

$html = file_get_html ($strFile);
$objHandle = opendir($strDir);
while(($strFile = readdir($objHandle)))
{
if($strFile != ".." && $strFile != ".")
{

$e = $html->find('table', 0)->find('pre', 0);
$body = '';
foreach ($e as $element)
$body .= '' . $element->plaintext . '';
$body .= '';
$html = str_get_html($body);
$html->save('$strDir.$strFile.txt');
}
}
closedir($objHandle);

?>


and thx inadvance for any help on this.

JAY6390
02-11-2010, 01:22 AM
Here's a fairly simple scandir function that you can use
http://lixlpixel.org/recursive_function/php/recursive_directory_scan/

whitevamp
02-11-2010, 04:17 AM
just wanted to say thanks JAY6390 for the script link.
it took me quite a wile trying to figure out how to get the two scripts to work together.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum