【问题标题】:Check if webpage contains text [closed]检查网页是否包含文字[关闭]
【发布时间】:2016-08-15 16:15:41
【问题描述】:

我正在获取一个使用 file_get_contents(); 的网页:

$file = file_get_contents('http://example.com');

如何检查网页是否包含文本“你好”或“再见”

【问题讨论】:

标签: php file-get-contents


【解决方案1】:
$file = file_get_contents('http://example.com');
$exists = (strpos($file, 'hello') !== false) || (strpos($file, 'bye') !== false);
if ($exists !== false) {
    print 'Found';
}

【讨论】:

  • 对不起,这个检查是看你好还是再见?
  • 是的,它会检查是否有你好或再见
  • 不,我的意思是它检查的是哪一个
  • @bobjomes 看代码,猜猜看!如果你不能解决这个问题,那么也许你需要找到另一个职业或爱好
  • @bobjomes 它会检查两者,如果找到 hello 或 bye Found 将被打印
【解决方案2】:
$file = file_get_contents('http://example.com');
if (strpos($file, 'hello') !== false)
{
    echo "Exist..";
}

【讨论】:

  • 对不起,这个检查是看你好还是再见?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-11
  • 1970-01-01
  • 2019-03-16
  • 1970-01-01
  • 2023-04-01
  • 1970-01-01
  • 2013-05-15
相关资源
最近更新 更多