array Validation errors list /** * Constructor, no parameters. */ public function __construct() { parent::__construct($this->host, 443, $this->timeout); } /** * HTML Document * * Returns an HTML document from a $fragment. * * @param string $fragment HTML content * @return string */ public function getDocument($fragment) { return '' . "\n" . '' . "\n" . '' . "\n" . 'validation' . "\n" . '' . "\n" . '' . "\n" . $fragment . "\n" . '' . "\n" . ''; } /** * HTML validation * * Performs HTML validation of $html. * * @param string $html HTML document * @param string $charset Document charset * @return boolean */ public function perform($html, $charset = 'UTF-8') { $this->setMoreHeader('Content-Type: text/html; charset=' . strtolower($charset)); $this->post($this->path, $html); if ($this->getStatus() != 200) { throw new Exception('Status code line invalid.'); } $result = $this->getContent(); if (strpos($result, '

The document validates according to the specified schema(s).

')) { return true; } else { if ($errors = preg_match('#(
    .*
)

There were errors.

#msU', $result, $matches)) { $this->html_errors = strip_tags($matches[1], '
  1. '); } return false; } } /** * Validation Errors * * @return array HTML validation errors list */ public function getErrors() { return $this->html_errors; } /** * Static HTML validation * * Static validation method of an HTML fragment. Returns an array with the * following parameters: * * - valid (boolean) * - errors (string) * * @param string $fragment HTML content * @param string $charset Document charset * @return array */ public static function validate($fragment, $charset = 'UTF-8') { $o = new self; $fragment = $o->getDocument($fragment, $charset); if ($o->perform($fragment, $charset)) { return ['valid' => true, 'errors' => null]; } else { return ['valid' => false, 'errors' => $o->getErrors()]; } } } /** @cond ONCE */ } /** @endcond */