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";
}
}
0
A
回答
6
我能想到的唯一的事情就是您使用的PHP 4不支持异常处理。所以它认为try
是某种常数,但不期望{
在那里。
您应该得到一个解析错误,而不是致命错误。
0
我将代码粘贴到一个新文件中并运行它:没有错误。问题可能在你的代码之上?
0
第14行之后的切换块。在catch块之前删除第二个}
1
该代码是100%有效的。也许错误在别处。在附注中,DOM函数不会抛出异常 - 您可能希望查看libxml_use_internal_errors
并将其设置为抛出异常。
相关问题
- 1. try catch块问题
- 2. 我的try catch块有什么问题? (文件I/O)
- 3. 在try..catch SQL问题
- 4. C++中的Try-Catch问题
- 5. T-SQL TRY CATCH的问题?
- 6. 这个try/except块在Python中有什么问题?
- 7. 为什么try块需要一个catch
- 8. 有人能澄清我这个try-catch块(未定义变量)有什么问题吗? (选择性捕捉,JS)
- 9. 为什么这个try-catch包装宏无法捕获异常?
- 10. 这个样本是否适合使用try catch?什么是sugesstions?
- 11. 为什么try/catch没有捕获访问冲突?
- 12. 的try-catch问题继承(JAVA)
- 13. 关于C++的一些问题try catch
- 14. 使用try-catch块的问题
- 15. 找不到符号问题try-catch
- 16. Android上的Try and Catch问题
- 17. 约try/catch语句简单的问题
- 18. try catch语句的作用域问题
- 19. TRY/CATCH_ALL vs try/catch
- 20. 解释Try try; Catch;
- 21. TRY CATCH
- 22. Try Catch does not catch
- 23. 这有什么问题?
- 24. 这里有什么问题?
- 25. 这些有什么问题?
- 26. 这里有什么问题
- 27. 这个PHP脚本有什么问题?
- 28. 这个功能有什么问题?
- 29. 这个jQuery代码有什么问题?
- 30. 这个OCaml代码有什么问题?
Works [here](http://ideone.com/PjAqO) – marcog 2011-01-14 20:56:12
您是不是偶然使用PHP 4? – NikiC 2011-01-14 20:57:44
这很奇怪。你确定你也检查过这个函数的代码吗?它可能会因为未关闭的函数而发生,if-clause等等 - 我不确定,但是这段代码看起来是正确的。编辑:marcog的回答也强调,它与这段代码无关。所以你应该去其他地方调查。 – Paul 2011-01-14 20:57:50