テキストの本文に対してテキストの文字列を実行して、テキストの文字列が特定のコンテキスト内 (この場合は h2 見出しタグ内) に存在するかどうかを判断しています。例を挙げると、XAMPP を使用して Win 7 で PHP 5.3 を実行しているアプリのローカルホスト インストールで完全に動作します。
ただし、HostGator で PHP 5.3.8 を実行しているライブ http サイトでこの同じコンテンツをテストすると、同じテストで偽陰性が得られます。
何か案は?コードは以下...
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;
}