| Conditions | 3 |
| Paths | 4 |
| Total Lines | 30 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | public function setContent($content) |
||
| 11 | { |
||
| 12 | require_once(HTML5LIB_PATH.'/HTML5/Parser.php'); |
||
|
|
|||
| 13 | |||
| 14 | // Convert any errors to exceptions |
||
| 15 | set_error_handler( |
||
| 16 | function ($no, $str) { |
||
| 17 | throw new Exception("HTML Parse Error: ".$str); |
||
| 18 | }, |
||
| 19 | error_reporting() |
||
| 20 | ); |
||
| 21 | |||
| 22 | // Use HTML5lib to parse the HTML fragment |
||
| 23 | try { |
||
| 24 | $document = \HTML5_Parser::parse( |
||
| 25 | '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head>'. |
||
| 26 | "<body>$content</body></html>" |
||
| 27 | ); |
||
| 28 | } catch (Exception $e) { |
||
| 29 | $document = false; |
||
| 30 | } |
||
| 31 | |||
| 32 | // Disable our error handler (restoring to previous value) |
||
| 33 | restore_error_handler(); |
||
| 34 | |||
| 35 | // If we couldn't parse the HTML, set the error state |
||
| 36 | if ($document) { |
||
| 37 | $this->setDocument($document); |
||
| 38 | } else { |
||
| 39 | $this->setInvalid(); |
||
| 40 | } |
||
| 43 |