Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php check if valid xml

/**
 * Class XmlParser
 * @author Francesco Casula <fra.casula@gmail.com>
 */
class XmlParser
{
    /**
     * @param string $xmlFilename Path to the XML file
     * @param string $version 1.0
     * @param string $encoding utf-8
     * @return bool
     */
    public function isXMLFileValid($xmlFilename, $version = '1.0', $encoding = 'utf-8')
    {
        $xmlContent = file_get_contents($xmlFilename);
        return $this->isXMLContentValid($xmlContent, $version, $encoding);
    }

    /**
     * @param string $xmlContent A well-formed XML string
     * @param string $version 1.0
     * @param string $encoding utf-8
     * @return bool
     */
    public function isXMLContentValid($xmlContent, $version = '1.0', $encoding = 'utf-8')
    {
        if (trim($xmlContent) == '') {
            return false;
        }

        libxml_use_internal_errors(true);

        $doc = new DOMDocument($version, $encoding);
        $doc->loadXML($xmlContent);

        $errors = libxml_get_errors();
        libxml_clear_errors();

        return empty($errors);
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: convert png to webp in php 
Php :: carbon add and subtract 
Php :: laravel logs 
Php :: array length php 
Php :: get date to current week last or first day dates 
Php :: PHP str_repeat — Repeat a string 
Php :: laravel model::query 
Php :: php mail if successful 
Php :: php prepared statement upload file 
Php :: Arr::only laravel 
Php :: laravel select 
Php :: eloquent first 
Php :: how run all seeder at once in laravel 
Php :: php contain 
Php :: php get variable by string name 
Php :: PHP array_merge() Function 
Php :: laravel access storage attachment 
Php :: How To Force Redirect HTTP To HTTPS In Laravel Using ServiceProvider 
Php :: laravel get all request parameters 
Php :: image upload in php code with databases 
Php :: php integer 
Php :: destruct php 
Php :: laravel custom validation rules 
Php :: php kommentar 
Php :: asin() php 
Php :: laravel relationship delete all 
Php :: cron job every 5 minutes wordpress 
Php :: where is in array laravel 
Php :: laravel check if primary key exists 
Php :: error laravel 404 in server 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =