-4

How can i check in PHP if a word exists in this website "url" or not.

For example, i have 4 sites that i want to check if the word "asus" exits in all of those sides of not and if exits count them !!

www.google.com
www.apple.com
www.microsoft.com
www.asus.com

i have tried in different different ways but no luck !!

How can i do that if PHP, DO ANYONE KNOWS !!!

I have search a lot but don't have the idea how to do that !!

Can someone please help me with this please

Istiak Mahmood
  • 2,330
  • 8
  • 31
  • 73
  • 2
    What have you tried so far? You need to make a get request to each, then check the returned source for the string. – Steve Nov 16 '15 at 13:16
  • Google gave me around 30 websites which perfectly explain what you want, so Im actually curious what you googled.. – Matheno Nov 16 '15 at 13:21

2 Answers2

1

You can use the strpos function which is used to find the occurrence of one string inside other:

if (strpos($url,'word') !== false) {
    echo 'true';
}

Source: How do I check if a string contains a specific word in PHP?

To find a word in a complete webpage use file_get_contents

$text = file_get_contents('http://www.url.com/');
echo (stristr ($text, 'word')) ? 'found' : 'not found';
Community
  • 1
  • 1
Matheno
  • 4,112
  • 6
  • 36
  • 53
1

Try like this..

$url1 = 'www.google.com';
$url2 = 'www.apple.com';
$url3 = 'www.microsoft.com';
$url4 = 'www.asus.com';

$word = 'asus';

if (strpos($url1, $word) !== false && strpos($url2, $word) !== false && strpos($url3, $word) !== false && strpos($url4, $word) !== false) {
    echo "$word Exist";
}else{
    echo "$word Not Exist";
}

Hope this will help

Amit Rajput
  • 2,061
  • 1
  • 9
  • 27