用于在网页上搜索单词的PHP脚本

时间:2011-06-13 12:50:37

标签: php html parsing

有人可以告诉我如何更改以下PHP脚本,如果网站http://www.stutteringjohnsmith.com中有“standup”字样,则说“找到”,如果不存在则说“找不到”

<?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];
?>

3 个答案:

答案 0 :(得分:5)

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

洛尔?

答案 1 :(得分:4)

<?php
$text = file_get_contents('http://www.stutteringjohnsmith.com/#/0');
echo (stristr ($text, 'standup')) ? 'found' : 'not found';
?>

答案 2 :(得分:1)

您正在使用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";
}