diff --git a/phpQuery/phpQuery/DOMDocumentWrapper.php b/phpQuery/phpQuery/DOMDocumentWrapper.php index 47ce35c..10e5fe5 100644 --- a/phpQuery/phpQuery/DOMDocumentWrapper.php +++ b/phpQuery/phpQuery/DOMDocumentWrapper.php @@ -164,7 +164,7 @@ protected function loadMarkupHTML($markup, $requestedCharset = null) { // Document Encoding Conversion // http://code.google.com/p/phpquery/issues/detail?id=86 if (function_exists('mb_detect_encoding')) { - $possibleCharsets = array($documentCharset, $requestedCharset, 'AUTO'); + $possibleCharsets = array($requestedCharset, $documentCharset, 'AUTO'); $docEncoding = mb_detect_encoding($markup, implode(', ', $possibleCharsets)); if (! $docEncoding) $docEncoding = $documentCharset; // ok trust the document @@ -194,9 +194,25 @@ protected function loadMarkupHTML($markup, $requestedCharset = null) { } phpQuery::debug("Full markup load (HTML), documentCreate('$charset')"); $this->documentCreate($charset); + if ($charset === 'utf-8') { + // Hack to load HTML as UTF-8 + $markup = '' . $markup; + } $return = phpQuery::$debug === 2 ? $this->document->loadHTML($markup) : @$this->document->loadHTML($markup); + if ($charset === 'utf-8') { + // Remove hack + foreach ($this->document->childNodes as $item) { + if ($item->nodeType == XML_PI_NODE) { + // remove hack + $this->document->removeChild($item); + } + } + // insert proper + $this->document->encoding = 'UTF-8'; + // End hack + } if ($return) $this->root = $this->document; } diff --git a/phpQuery/phpQuery/Zend/Json/Decoder.php b/phpQuery/phpQuery/Zend/Json/Decoder.php index b9bf8ba..c5f1f25 100644 --- a/phpQuery/phpQuery/Zend/Json/Decoder.php +++ b/phpQuery/phpQuery/Zend/Json/Decoder.php @@ -19,7 +19,7 @@ */ /** - * @see Zend_Json + * @see Zend_Json */ require_once 'Zend/Json.php'; diff --git a/test-cases/run.php b/test-cases/run.php index 240fdea..eb33fa0 100644 --- a/test-cases/run.php +++ b/test-cases/run.php @@ -1,11 +1,11 @@ - \ No newline at end of file diff --git a/test-cases/test_2.php b/test-cases/test_2.php index 4b82993..f1e2ec4 100644 --- a/test-cases/test_2.php +++ b/test-cases/test_2.php @@ -1,20 +1,20 @@ find('p') - ->filter('.body:gt(1)'); -if ( $result->whois() == $testResult ) - print "Test '{$testName}' PASSED :)"; -else +); +$result = phpQuery::newDocumentFile('test.html'); +$result = $result->find('p') + ->filter('.body:gt(1)'); +if ( $result->whois() == $testResult ) + print "Test '{$testName}' PASSED :)"; +else print "Test '{$testName}' FAILED !!! "; -print_r($result->whois()); +print_r($result->whois()); print "\n"; diff --git a/test-cases/test_document.php b/test-cases/test_document.php index 24c2cc5..901b902 100644 --- a/test-cases/test_document.php +++ b/test-cases/test_document.php @@ -1,6 +1,6 @@ find('li:first')->html('foo
bar
foo foo')->html(); die(); -$testResult = 10; -if ($doc->script('example', 'p')->length == $testResult) - print "Test '$testName' PASSED :)"; -else { +$testResult = 10; +if ($doc->script('example', 'p')->length == $testResult) + print "Test '$testName' PASSED :)"; +else { print "Test '$testName' FAILED !!! "; print ""; - var_dump($doc->whois()); + var_dump($doc->whois()); print "\n"; } print "\n"; \ No newline at end of file diff --git a/test-cases/test_scripts.php b/test-cases/test_scripts.php index 490e309..c87c9c7 100644 --- a/test-cases/test_scripts.php +++ b/test-cases/test_scripts.php @@ -1,19 +1,19 @@ script('example', 'p')->length == $testResult) - print "Test '$testName' PASSED :)"; -else { +$testResult = 10; +if ($doc->script('example', 'p')->length == $testResult) + print "Test '$testName' PASSED :)"; +else { print "Test '$testName' FAILED !!! "; print "
"; - var_dump($doc->whois()); + var_dump($doc->whois()); print "\n"; } print "\n"; @@ -34,5 +34,5 @@ var_dump($doc->whois()); print "\n"; } -print "\n"; +print "\n"; ?> \ No newline at end of file diff --git a/test-cases/test_selectors.php b/test-cases/test_selectors.php index 2332d1a..1aad964 100644 --- a/test-cases/test_selectors.php +++ b/test-cases/test_selectors.php @@ -1,91 +1,91 @@ $test ) { - $tests[ $k ][2] = pq( $test[0] )->whois(); -} -foreach( $tests as $test ) { - if ( $test[1] == $test[2] ) - print "Test '{$test[0]}' PASSED :)"; - else { - print "Test '{$test[0]}' FAILED !!!"; - print_r($test[2]); - } - print "