尝试捕获有什么问题?

Sco*_*t B 0 php

function rseo_get_seo($check, $post){
//code breaks somewhere in here. or in the rseo_doTheParse function.
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){
    try { //I get a FATAL error here. unexpected '{'
        $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.'")])');
        }
    }
    catch (Exception $e)
    {
        echo 'Exception caught: ',  $e->getMessage(), "\n";
    }
}
Run Code Online (Sandbox Code Playgroud)

Bol*_*ock 6

我唯一能想到的是你使用的是PHP 4,它不支持异常处理.所以它认为try是某种常数,但不要指望它{在那里.

你应该得到一个解析错误,而不是一个致命的错误.