特殊字符解析(ü,ä等).适用于本地主机,而不是http


Special characters parsing (ü,ä, etc). Works on localhost, not http

我正在对文本体运行文本字符串,以确定该文本字符串是否存在于特定上下文中(在本例中,在h2标题标记中)。我可以举一个例子,它可以完美地在本地主机安装我的应用程序,在win7上运行PHP 5.3与XAMPP

然而,当我在一个实时http站点上测试相同的内容时,在HostGator上运行PHP 5.3.8,我在相同的测试中得到假阴性。

任何想法?代码如下…

Keyword: Flirttipps für Männer
Content: <h2>Flirttipps für Männer</h2>

function doTheParse($heading='h2', $post) {
    //$content = $post->post_content;
    $content = '<h2>Flirttipps für Männer</h2>';
    $keyword = sanitize_string( trim(strtolower(getKeyword($post))) );
    $keyword = sanitize2($keyword);
    @$dom = new DOMDocument;
    @$dom->loadHTML(sanitize_string( strtolower($content) ));
    $xPath = new DOMXPath(@$dom);
    switch ($heading) {
        case "img-alt": 
            return $xPath->evaluate('boolean(//img[contains(@alt, "'.$keyword.'")])');
        default: 
            return $xPath->evaluate('boolean(/html/body//'.$heading.'[contains(.,"'.$keyword.'")])');
    }
}
function getKeyword($post) {
    global $spec;
    $myKeyword = get_post_meta($post->ID, 'my_keyword', true);
    if(isset($spec['keyword_default']) && $myKeyword == ""){$myKeyword = $post->post_title;}
    $myKeyword = htmlspecialchars_decode($myKeyword);
    return " ".$myKeyword;
}
function sanitize_string( $content ) {
    $regex = '/( ['x00-'x7F] | ['xC0-'xDF]['x80-'xBF] | ['xE0-'xEF]['x80-'xBF]{2} | ['xF0-'xF7]['x80-'xBF]{3} ) | ./x';
    return preg_replace($regex, '$1', $content);
}
function sanitize2($s) {
    $result = preg_replace("/[^'p{Latin}0-9&'-]+/u", " ", html_entity_decode($s, ENT_QUOTES));
    return $result;
}

检查区域设置,例如setLocale()。根据语言设置,许多函数的工作方式不同。