2013-04-10 105 views
0

我使用phpQuery从基于用户输入的页面刮取一些信息,但我试图设置错误处理,如果用户输入一些不存在的东西。phpQuery错误处理

例如,用户输入不正确的产品数量可能会导致

Warning: file_get_contents([function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in 

我可以在if语句中使用什么在这样一个实例来检查phpQuery错误?

例如

if(...error...){ 
    echo json_encode("error" => 'Incorrect value entered'); 
} 

回答

1

尝试围绕你打算在一个try-catch块的输入使用的逻辑。

喜欢的东西:

try { 
    <..insert your logic here..> 
} catch (Exception $e) { 
    echo json_encode("error" => "Incorrect value entered"); 
}