【问题标题】:PHP to get contents of a URL and search within it to echo the resultPHP 获取 URL 的内容并在其中搜索以回显结果
【发布时间】:2014-05-08 12:12:31
【问题描述】:

使用 php,我正在尝试创建一个脚本,该脚本将抓取 url 的所有内容,然后在其中搜索字符串并在找到匹配项时回显。

假设我有一个 url (http://www.mydomain.com),在这个 url 中,有一个字符串存储在其中,它也是 'http://www.mydomain.com'。我想获取http://www.mydomain.com 的内容并检查其源代码中是否存在“http://www.mydomain.com”。

【问题讨论】:

  • 一起使用curlDOMDocument

标签: php url search echo file-get-contents


【解决方案1】:

试试这个代码

<?php
$homepage = file_get_contents('http://www.mydomain.com/');
if (strpos($homepage,'http://www.mydomain.com/') !== false) {
    echo 'true';
}

享受:)

【讨论】:

  • 有时你只需要从头开始思考,谢谢!成功了!
【解决方案2】:
$content = file_get_contents('http://someurl.com');
$pos = strpos($content, 'Some String');
if($pos!==false){
echo 'String Exists';
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-29
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-30
    相关资源
    最近更新 更多