Skip to content

Instantly share code, notes, and snippets.

@batuhan
Created August 17, 2011 17:11
Show Gist options
  • Save batuhan/1152044 to your computer and use it in GitHub Desktop.
Save batuhan/1152044 to your computer and use it in GitHub Desktop.
Is offensive?
<?php
//checks if text contains any offensive words, returns boolean.
function is_offensive($text){
$data = file_get_contents('http://www.wdyl.com/profanity?q='.$text);
$data = json_decode($data);
return $data->response;
}
//Example
$text = 'Fuck it, I'll watch some porn'; // will return true
#$text = 'Nevermind, I'll watch Mythbusters'; // should return false
if(is_offensive($text) === TRUE){
echo 'contains some bad words!';
}else{
echo 'It\'s clean!';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment