我的 PHP 代码:
include 'simple_html_dom.php';
$value1 = "http://isitraining.in/$message";
$html = file_get_html($value1);
$rain = $html->find('h1');
$weather = $html->find('h2');
$rains = strip_tags($rain[0]);
weathers = strip_tags($weather[0]);
它适用于有效的城市名称 $message=london;
如果不是有效的城市名称,如果 $message=abc;
它像这样返回:
Fatal error: Call to a member function find() on a non-object
我的 HTML 源代码:
$message=abc;
<h1>Oops!</h1>
<h2>No results! There might be something wrong with the city name..</h2>
如果$消息=伦敦;
<h1>No</h1>
<h2>Conditions for <strong>London, England, United Kingdom</strong><br/>on Fri, 16 Aug 2013 2:18 pm BST: <strong>Mostly Cloudy</strong> (22°C, 70°F)</h2>