【问题标题】:PHP Script to search for word on web page用于在网页上搜索单词的 PHP 脚本
【发布时间】:2013-06-03 04:03:52
【问题描述】:

如果网站http://www.stutteringjohnsmith.com 中包含“standup”一词,请告诉我如何更改以下 PHP 脚本以显示“找到”,如果没有则显示“未找到”

<?php
$data = file_get_contents('http://www.stutteringjohnsmmith.com/#/0');
$regex = '/Page 1 of (.+?) results/';
preg_match($regex,$data,$match);
var_dump($match);
echo $match[1];
?>

【问题讨论】:

    标签: php html parsing


    【解决方案1】:
    <?php
    $data = file_get_contents('http://www.stutteringjohnsmmith.com/#/0');
    $regex = '/standup/';    //<----
    preg_match($regex,$data,$match);
    var_dump($match);
    echo $match[1];
    ?>
    

    哈哈?

    【讨论】:

      【解决方案2】:
      <?php
      $text = file_get_contents('http://www.stutteringjohnsmith.com/#/0');
      echo (stristr ($text, 'standup')) ? 'found' : 'not found';
      ?>
      

      【讨论】:

        【解决方案3】:

        您正在使用 wordpress 域 (http://stutteringjohnsmith.wordpress.com/)

        以下将起作用:

        $data = file_get_contents('http://stutteringjohnsmith.wordpress.com/');
        $regex = '/standup/';    
        
        if (preg_match($regex, $data)) {
            echo "found";
        } else {
            echo "not found";
        }
        

        【讨论】:

          最近更新 更多