SJS
SJS

Reputation: 5667

PHP Script to search for word on web page

Can someone please show me how to change the following PHP script to say "found" if the site http://www.stutteringjohnsmith.com has the word "standup" in it and to say "not found" if it does not

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

Upvotes: 3

Views: 10598

Answers (3)

Tomasz Durka
Tomasz Durka

Reputation: 586

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

Upvotes: 4

Tieme
Tieme

Reputation: 65409

You are using a wordpress Domain (http://stutteringjohnsmith.wordpress.com/)

The following will work:

$data = file_get_contents('http://stutteringjohnsmith.wordpress.com/');
$regex = '/standup/';    

if (preg_match($regex, $data)) {
    echo "found";
} else {
    echo "not found";
}

Upvotes: 1

dynamic
dynamic

Reputation: 48131

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

lol?

Upvotes: 6

Related Questions