1252748
1252748

Reputation: 15372

variable constantly retaining value once set

I'm looping through a directory, trying to find XML files with errors.

$baddies = array();
foreach (glob("fonts/*.svg") as $filename) {

    libxml_use_internal_errors(true);

    $str = file_get_contents($filename);

    $sxe = simplexml_load_string($str);

    $errors = libxml_get_errors();

    $num_of_errors = 0;
    $num_of_errors = sizeof($errors);

    if ($num_of_errors > 0){

        array_unshift($baddies, $filename);

    }

 }

However it seems that once the errors are put into this object, they persist there through subsequent iterations of the loop, and files without errors still test positive. $num_of_errors remains high for good files. I have it being reset to zero, and have even tried unseting it after each time through the loop. I suppose libxml_get_errors continues to retain a value once set. How can I reset it?

Upvotes: 1

Views: 28

Answers (1)

Vivek Vaghela
Vivek Vaghela

Reputation: 1075

I think you should use libxml_clear_errors function. As per document here it says, the function keeps the errors stored in buffer.

Upvotes: 1

Related Questions