Hi, what is good code to show some part of webpage onyl if URL is free from certain phrasses?

ie: i have Adsense and i dont want to show ads on pages where in url is "porn", "cigar"

so far i found this working html/javascript code (can be inserted into html webpage or php webpage.

<div id="conditionalbox">
Visible only if phrasses do not exist in URL
if (/porn|cigar|drug|sex/.test(window.location.href)) {
document.getElementById('conditionalbox').style.display = 'none';
and also this pure php code:

$url = "http://' . $SERVER['SERVERNAME'] . $SERVER['REQUESTURI'];";
$match = false;
$wordlist = array('motorcycles','car');
foreach ($wordlist as $w) {
  if (false !== strpos($url,$w)) {
  $match = true;
if ($match) {
  echo 'At least one word matched';
} else {
  echo 'No match';
(beware of first line about quotation marks, can be wrong)

So it will hide some content if bad words are in URL, but what about hiding content if badwords are in page body?

Similar topic: Show code only if PAGE CONTENT is free from bad words