-
How To Check For Banned Word On Page With Javascript ?
about 7 years ago
-
about 7 years ago
Folks!
Why do you reckon this code does not work ? I only see a blank page.
The code will need to run everytime cURL loads a page so that the JS can check the page for banned words.
[code]
<?php
/*
ERROR HANDLING
*/
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://www.buzzfeed.com/mjs538/the-68-words-you-cant-say-on-tv?utm_term=.xlN0R1Go89#.pbdl8dYm3X');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true );
$result = curl_exec($curl);
if (curl_errno($curl)) {
echo 'Error:' . curl_error($curl);
}
$response = curl_getinfo( $curl );
if($response['http_code'] == '200' )
{
?>
<script>
$(function(){
var pageData = "hello <a>example can have tags! swear word is </a><div> one..</div>";
if(checkSwear(pageData)== false){
//redirect to google
}
});
function checkSwear(sentance) {
var swear_words_arr=new Array("blow", "nut", "asshole");
var regex = new RegExp('\\b(' + swear_words_arr.join('|') + ')\\b', 'i' );
if(regex.test(sentance)) {
alert("Please refrain from using offensive words"); /* + alert_text */
return false;
} else {
//alert(1)
return true;
}
}
</script>
<?php
}
curl_close($curl);
?>
[/code] -
-
about 7 years ago
@UniqueIdeaMan I have written a fiddle that will help you implement your logic.
or
You can use the jQuery library for profanity filter. here is the link:
https://github.com/ChaseFlorell/jQuery.ProfanityFilter
-
2 Answer(s)