1
0
mirror of https://github.com/moparisthebest/wallabag synced 2024-11-27 11:22:17 -05:00

update JSLikeHTMLElement

This commit is contained in:
nicosomb 2013-04-24 08:27:55 +02:00
parent 494e21b4da
commit baa8617364

View File

@ -4,7 +4,7 @@
* *
* This class extends PHP's DOMElement to allow * This class extends PHP's DOMElement to allow
* users to get and set the innerHTML property of * users to get and set the innerHTML property of
* HTML elements in the same way it's done in * HTML elements in the same way it's done in
* JavaScript. * JavaScript.
* *
* Example usage: * Example usage:
@ -15,16 +15,16 @@
* $doc->registerNodeClass('DOMElement', 'JSLikeHTMLElement'); * $doc->registerNodeClass('DOMElement', 'JSLikeHTMLElement');
* $doc->loadHTML('<div><p>Para 1</p><p>Para 2</p></div>'); * $doc->loadHTML('<div><p>Para 1</p><p>Para 2</p></div>');
* $elem = $doc->getElementsByTagName('div')->item(0); * $elem = $doc->getElementsByTagName('div')->item(0);
* *
* // print innerHTML * // print innerHTML
* echo $elem->innerHTML; // prints '<p>Para 1</p><p>Para 2</p>' * echo $elem->innerHTML; // prints '<p>Para 1</p><p>Para 2</p>'
* echo "\n\n"; * echo "\n\n";
* *
* // set innerHTML * // set innerHTML
* $elem->innerHTML = '<a href="http://fivefilters.org">FiveFilters.org</a>'; * $elem->innerHTML = '<a href="http://fivefilters.org">FiveFilters.org</a>';
* echo $elem->innerHTML; // prints '<a href="http://fivefilters.org">FiveFilters.org</a>' * echo $elem->innerHTML; // prints '<a href="http://fivefilters.org">FiveFilters.org</a>'
* echo "\n\n"; * echo "\n\n";
* *
* // print document (with our changes) * // print document (with our changes)
* echo $doc->saveXML(); * echo $doc->saveXML();
* @endcode * @endcode
@ -59,7 +59,7 @@ class JSLikeHTMLElement extends DOMElement
$value = mb_convert_encoding($value, 'HTML-ENTITIES', 'UTF-8'); $value = mb_convert_encoding($value, 'HTML-ENTITIES', 'UTF-8');
// Using <htmlfragment> will generate a warning, but so will bad HTML // Using <htmlfragment> will generate a warning, but so will bad HTML
// (and by this point, bad HTML is what we've got). // (and by this point, bad HTML is what we've got).
// We use it (and suppress the warning) because an HTML fragment will // We use it (and suppress the warning) because an HTML fragment will
// be wrapped around <html><body> tags which we don't really want to keep. // be wrapped around <html><body> tags which we don't really want to keep.
// Note: despite the warning, if loadHTML succeeds it will return true. // Note: despite the warning, if loadHTML succeeds it will return true.
$result = @$f->loadHTML('<htmlfragment>'.$value.'</htmlfragment>'); $result = @$f->loadHTML('<htmlfragment>'.$value.'</htmlfragment>');
@ -86,7 +86,7 @@ class JSLikeHTMLElement extends DOMElement
* @code * @code
* $string = $div->innerHTML; * $string = $div->innerHTML;
* @endcode * @endcode
*/ */
public function __get($name) public function __get($name)
{ {
if ($name == 'innerHTML') { if ($name == 'innerHTML') {
@ -106,5 +106,4 @@ class JSLikeHTMLElement extends DOMElement
{ {
return '['.$this->tagName.']'; return '['.$this->tagName.']';
} }
} }
?>