moonorongo
4/26/2017 - 11:35 AM

[svgClean()] Funcion para limpiar un svg de basura #php #svg #functions

[svgClean()] Funcion para limpiar un svg de basura #php #svg #functions

<?php
    function svgClean($svgFile) 
    {
    	$regexComment = '/\s*\<\!\-\-((?!\-\-\>)[\s\S])*\-\-\>\s*/i';
        $regexEncoding = '/\s*\<\?xml((?!\"\?\>)[\s\S])*\"\?\>*/i';
        $regexDoctype = '/\s*\<\!DOCTYPE\s((?!\.dtd\"\>)[\s\S])*\.dtd\"\>*/i';

        $xml = file_get_contents($svgFile);
        $xml = preg_replace ($regexEncoding, '', $xml);
        $xml = preg_replace ($regexDoctype, '', $xml);
        $xml = preg_replace ($regexComment, '', $xml);
            
        return $xml;
    }