Check if string exists in a web page

后端 未结 1 1171
执笔经年
执笔经年 2021-02-11 10:09

I\'m trying to use curl to detect whether a piece of text exists in the source code of a remote webpage. For example, I\'m trying to see if this string exists in the source:

相关标签:
1条回答
  • 2021-02-11 11:05

    The two functions you need are cURL and strpos().

    <?php
    $ch = curl_init("http://www.example.com");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $text = curl_exec($ch);
    $test = strpos($text, "<!-- BEGIN TEST CODE -->");
    if ($test==false)
    {
        echo "no";
    }
    else
    {
        echo "yes";
    }
    ?>
    
    0 讨论(0)
提交回复
热议问题