이 코드는 워드 프레스 플러그인의 일부입니다. 페이지는 두 번째 기능의 어딘가에서 깨지고 그 지점에서 페이지 출력을 중단합니다.이 코드는 PHP4를 어떻게 나눕니까?
나는이 문제가 PHP4라고 판단했다. PHP4에서 지원하지 않는다면 DOMDocument 호출을 추측하고 있습니다.
그렇다면 호환성을 테스트하고 try/catch없이 페이지를 고정하지 않고 정상적으로 종료하려면 어떻게해야합니까?
function rseo_get_seo($check, $post){
switch ($check)
{
case "h1": return rseo_doTheParse('h1', $post);
case "h2": return rseo_doTheParse('h2', $post);
case "h3": return rseo_doTheParse('h3', $post);
case "img-alt": return rseo_doTheParse('img-alt', $post);
}
}
function rseo_doTheParse($heading, $post){
//code breaks somewhere in here and freezes output of page. How can I error check this without try/catch?
$content = $post->post_content;
if($content=="") return false;
$keyword = trim(strtolower(rseo_getKeyword($post)));
@$dom = new DOMDocument;
@$dom->loadHTML(strtolower($post->post_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.'")])');
}
}
함수 호출 앞에있는'@'을 제거하고 오류보고를 활성화하여 오류를 확인하십시오. –
잠깐, 나는'case'가 항상'break'를 필요로한다고 생각했다. 그렇지 않으면 적절한'case' 아래의 모든 경우를 실행할 것이다. – Ben
호스트가 PHP 4에서 PHP 5로 전환 할 수있는 옵션을 제공합니까? – BoltClock