Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

php help...

Featured Replies

I fudged this script together to check a websites body content and generate a message whether a keyword is present more than twice. only it breaks and doesn't work if the "keyword" is more than one word.

 

How to I make it work so it can cater for multiple words within the "keyword"

 

<?php
$keyword = ($_POST['keyword']); // defined by form
$domainname = ($_POST['url']); // defined by form

$file = file_get_contents($domainname);
$body = preg_replace("/.*<body[^>]*>|<\/body>.*/si", "", $file);{
$bodyp = strip_tags($file);
if (substr_count(strtolower($bodyp), strtolower($keyword)) > 2 ){
       echo "<span class='good'>Yes. </span>Awesome, your keyword is present in the body of your content.";
       }
else {
              echo "<span class='bad'>No. </span>You should really have the keyword your looking for in content of your website.";
       }
      }
?>

 

Cheers people (^_^)

Personally I'd strip all HTML tags using strip_tags() then compare that string using strpos()

  • Author

Personally I'd strip all HTML tags using strip_tags() then compare that string using strpos()

 

I have striped all html tags...

 

$bodyp = strip_tags($file);

 

When I echo out the result ($bodyp) I get text..which has the two word keyword in, but it tell me that its not there.

I dont know much about substr_count but I suggested using strpos as an alternative, for example...

 

<?php

$keyword = ($_POST['keyword']); // defined by form
$domainname = ($_POST['url']); // defined by form

//tests
$domainname = 'http://news.bbc.co.uk/sport1/hi/football/scot_prem/9028899.stm'; 
$keyword = "kenny miller";

function keyWordCount($keyword, $body) {

   $found = $offset = 0;

   while(!(strpos($body, $keyword, $offset) === false)) {
       $found++;
       $offset = strpos($body, $keyword, $offset)+1;
   }

   return $found;

} 

$file = file_get_contents($domainname);
$body = preg_replace("/.*<body[^>]*>|<\/body>.*/si", "", $file); //this is EXTREMELY CPU intensive!
$bodyp = strip_tags($body);

if (keyWordCount(strtolower($keyword), strtolower($bodyp)) > 2 ) {
   echo "<span class='good'>Yes. </span>Awesome, your keyword is present in the body of your content.";
} else {
   echo "<span class='bad'>No. </span>You should really have the keyword your looking for in content of your website.";
}
?>

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.