1 : <?php
2 : /**
3 : * Load FluentDOM from HTML string
4 : *
5 : * @version $Id: StringHTML.php 305 2009-07-24 18:03:59Z subjective $
6 : * @license http://www.opensource.org/licenses/mit-license.php The MIT License
7 : * @copyright Copyright (c) 2009 Bastian Feder, Thomas Weinert
8 : *
9 : * @package FluentDOM
10 : * @subpackage Loaders
11 : */
12 :
13 : /**
14 : * include interface
15 : */
16 : require_once dirname(__FILE__).'/../FluentDOMLoader.php';
17 :
18 : /**
19 : * Load FluentDOM from HTML string
20 : *
21 : * @package FluentDOM
22 : * @subpackage Loaders
23 : */
24 : class FluentDOMLoaderStringHTML implements FluentDOMLoader {
25 :
26 : /**
27 : * load DOMDocument from html string
28 : *
29 : * @param string $source html string
30 : * @param string $contentType
31 : * @access public
32 : * @return object DOMDocument | FALSE
33 : */
34 : public function load($source, $contentType) {
35 3 : if (is_string($source) &&
36 2 : FALSE !== strpos($source, '<') &&
37 3 : $contentType == 'text/html') {
38 1 : $dom = new DOMDocument();
39 1 : $errorSetting = libxml_use_internal_errors(TRUE);
40 1 : libxml_clear_errors();
41 1 : $dom->loadHTML($source);
42 1 : libxml_clear_errors();
43 1 : libxml_use_internal_errors($errorSetting);
44 1 : return $dom;
45 : }
46 2 : return FALSE;
47 : }
48 : }
49 :
|