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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.