Fli
11-14-2014, 01:48 AM
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
</div>
<script>
if (/porn|cigar|drug|sex/.test(window.location.href)) {
document.getElementById('conditionalbox').style.di splay = 'none';
}
</script>
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 (http://internetlifeforum.com/showthread.php?t=4463&p=7139#post7139)
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
</div>
<script>
if (/porn|cigar|drug|sex/.test(window.location.href)) {
document.getElementById('conditionalbox').style.di splay = 'none';
}
</script>
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 (http://internetlifeforum.com/showthread.php?t=4463&p=7139#post7139)