Jump to content

how to find specific characters in file


paulus4605

Recommended Posts

The goal of this excercise is to find "invalid characters" in a given file

 

the characters that I am refering to are éèàëöï&ê

 

I have this code at the moment that checks if the structure of the file is a valid xml file

 

However the part where I want to check the content of the same xml file for the above mentioned characters I don't get any errors dispite the fact that I put these characters in the file

 

<?php
header( 'Content-Type: text/html; charset=UTF-8;' );
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT); 
$xdoc = new DomDocument;
$xmlfile = 'Testpayment.xml';
$xmlschema = './xmlschemes/pain.001.001.02.xsd';
//Load the xml document in the DOMDocument object
$xdoc->Load($xmlfile);
//Validate the XML file against the schema
if ($xdoc->schemaValidate($xmlschema)) {
print "$xmlfile is valid.\n";
} else {
print "$xmlfile is invalid.\n";
}
echo '<pre>';
$xmlfile = array();
foreach ( $xmlfile as $string )
{
    if (preg_match( '#^[a-z0-9/?:.( ),\' +-]*$#i', $string ) )
    {
        echo 'GOED';
    }
    else
    {
        echo 'FOUT';
    }
    echo ' ' . $string . PHP_EOL;
}
echo '</pre>';
?>

 

What am I doing wrong here?

Link to comment
https://forums.phpfreaks.com/topic/247172-how-to-find-specific-characters-in-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.