I have the following function :
function doParse($parser_object) {
$links=file("./fullsoccer.TXT", "r");
$i=0;
while(!empty($links[$i]))
{
set_time_limit(0);
if (!($fp = fopen($links[$i], "r")));
{
//loop through data
while ($data = fread($fp, 4096)) {
//parse the fragment
xml_parse($parser_object, $data, feof($fp));
}
}
$i++;
}
}
This code save a list of 507 links of XML data from fullsocce.txt into $links then I read the content of each file (link: online links) using fread and pass the $data to my main function which is xml_parse to parse and save the data using SAX parser . my problem is: just that last file of the array $links is passed to the function and parse the data , I want your help to know why it is working just with one file? please It is an emergency case
!($fp = fopen($links[$i], "r")
fopen returns FALSE on error so this check is only true at eof or an invild line. Maybe changing it to
if (($fp = fopen($links[$i], "r") != FALSE)
I also noticed an extra ; and ) in if (!($fp = fopen($links[$i], "r"))); Maybe I'm just not matching properly.
you are missing fclose
, but other than that I think you need to do some debugging, try comment out the "xml_parse" function and add echo $links[$i]."<br /> ";
function doParse($parser_object) {
$links=file("./fullsoccer.TXT", "r");
$i=0;
foreach($links as $link)
{
set_time_limit(0);
echo 'reading '.$link."
";
$fp = fopen($link, "r");
if ($fp!==false)
{
//loop through data
while ($data = fread($fp, 4096)) {
//parse the fragment
//xml_parse($parser_object, $data, feof($fp));
echo $data;
}
echo "
";
fclose($fp);
} else {
echo 'Cannot Open Link '.$link."
";
}
$i++;
}
}