src/Sanitizer.php
public function sanitize($dirty)
    {
        // Don't run on an empty string
        if (empty($dirty)) {
            return '';
        }

        // Strip php tags
        $dirty = preg_replace('/<\?(=|php)(.+?)\?>/i', '', $dirty);

        $this->resetInternal();
        $this->setUpBefore();

        $loaded = $this->xmlDocument->loadXML($dirty);

        // If we couldn't parse the XML then we go no further. Reset and return false
        if (!$loaded) {
            $this->resetAfter();
            return false;
        }

        $this->removeDoctype();

        // Grab all the elements
        $allElements = $this->xmlDocument->getElementsByTagName("*");

        // Start the cleaning proccess
        $this->startClean($allElements);

        // Save cleaned XML to a variable
        if ($this->removeXMLTag) {
            $clean = $this->xmlDocument->saveXML($this->xmlDocument->documentElement, $this->xmlOptions);
        } else {
            $clean = $this->xmlDocument->saveXML($this->xmlDocument, $this->xmlOptions);
        }

        $this->resetAfter();

        // Remove any extra whitespaces when minifying
        if ($this->minifyXML) {
            $clean = preg_replace('/\s+/', ' ', $clean);
        }

        // Return result
        return $clean;
    }
public function sanitize($dirty)
    {
        // Don't run on an empty string
        if (empty($dirty)) {
            return '';
        }

        // Strip php tags
        $dirty = preg_replace('/<\?(=|php)(.+?)\?>/i', '', $dirty);

        $this->resetInternal();
        $this->setUpBefore();

        $loaded = $this->xmlDocument->loadXML($dirty);

        // If we couldn't parse the XML then we go no further. Reset and return false
        if (!$loaded) {
            $this->resetAfter();
            return false;
        }

        $this->removeDoctype();

        // Grab all the elements
        $allElements = $this->xmlDocument->getElementsByTagName("*");

        // Start the cleaning proccess
        $this->startClean($allElements);

        // Save cleaned XML to a variable
        if ($this->removeXMLTag) {
            $clean = $this->xmlDocument->saveXML($this->xmlDocument->documentElement, $this->xmlOptions);
        } else {
            $clean = $this->xmlDocument->saveXML($this->xmlDocument, $this->xmlOptions);
        }

        $this->resetAfter();

        // Remove any extra whitespaces when minifying
        if ($this->minifyXML) {
            $clean = preg_replace('/\s+/', ' ', $clean);
        }

        // Return result
        return $clean;
    }
public function sanitize ( $ dirty ) { // Don't run on an empty string if ( empty ( $ dirty ) ) { return '' ; } // Strip php tags $ dirty = preg_replace ( '/<\?(=|php)(.+?)\?>/i' , '' , $ dirty ) ; $ this -> resetInternal ( ) ; $ this -> setUpBefore ( ) ; $ loaded = $ this -> xmlDocument -> loadXML ( $ dirty ) ; // If we couldn't parse the XML then we go no further. Reset and return false if ( ! $ loaded ) { $ this -> resetAfter ( ) ; return false ; } $ this -> removeDoctype ( ) ; // Grab all the elements $ allElements = $ this -> xmlDocument -> getElementsByTagName ( "*" ) ; // Start the cleaning proccess $ this -> startClean ( $ allElements ) ; // Save cleaned XML to a variable if ( $ this -> removeXMLTag ) { $ clean = $ this -> xmlDocument -> saveXML ( $ this -> xmlDocument -> documentElement , $ this -> xmlOptions ) ; } else { $ clean = $ this -> xmlDocument -> saveXML ( $ this -> xmlDocument , $ this -> xmlOptions ) ; } $ this -> resetAfter ( ) ; // Remove any extra whitespaces when minifying if ( $ this -> minifyXML ) { $ clean = preg_replace ( '/\s+/' , ' ' , $ clean ) ; } // Return result return $ clean ; }
Sanitize the passed string

@param string $dirty
@return string
Sanitize the passed string