Skip to content

request charset not work  #2

@tablecell

Description

@tablecell

here is test code
utf8.php

<?php
require('phpQuery/phpQuery.php');
$html=<<<D
<!doctype html>
<html lang="en">
 <head>
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>中文ABC</title>
 </head>
 <body>

 </body>
</html>
D;
$doc = phpQuery::newDocumentHTML($html,'utf8');
echo $doc->find("title");

result is

 <title>中�ABC</title> 

addCharset

$doc = phpQuery::newDocumentHTML('<meta charset="utf8">'.$html,'utf8');
echo $doc->find("title");

result is

<title>中�ABC</title>>Exit code: 0

the file is saved as utf8 format
DOMDocumentWrapper.php
line 155

        $addDocumentCharset = false;
        if ($documentCharset) {
            $charset = $documentCharset;
            $markup = $this->charsetFixHTML($markup);
        } else if ($requestedCharset) {
            $charset = $requestedCharset;
        }

        if (! $charset)
            $charset = phpQuery::$defaultCharset;
        // HTTP 1.1 says that the default charset is ISO-8859-1
        // @see http://www.w3.org/International/O-HTTP-charset
        if (! $documentCharset) {
            $documentCharset = 'ISO-8859-1';
            $addDocumentCharset = true; 
        }

if $documentCharset no support ,can $requestedCharset overfide $documentCharset ?
can

$documentCharset is page embed contenttype meta like " "
$requestedCharset is user parameter like

 $requestedCharset ='utf8';
$doc = phpQuery::newDocumentHTML($html, $requestedCharset);

what's $charset stand for
the get charset logic is
page embed meta charset ?
        ----> user $requestedCharset; ?
                    ---> $charset = phpQuery::$defaultCharset;

why

if (! $documentCharset) {
            $documentCharset = 'ISO-8859-1';
            $addDocumentCharset = true; 
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions