PHP Code Sample

To perform a very simple request in PHP, your code might look like this:

PHP 5.X

$checkurl = "http://www.webpurify.com/services/rest/?method=webpurify.live.check&api_key=[API KEY]&text=".urlencode('test test test');
$response = simplexml_load_file($checkurl,'SimpleXMLElement', LIBXML_NOCDATA);
echo $response->found;

PHP 4.X

function ParseXML($xml) {
// Gets XML in a string and parses it into an array.

// Create the parser object
if (!($parser = xml_parser_create())) {
    print "cannot create parser!";
    exit();
}

// if we didn't get the argument then give them an error.
if ($xml == "") {
    print "No XML Was found!";
    exit;
}

xml_parse_into_struct($parser, trim($xml), &$structure, &$index);
xml_parser_free($parser);

// the parsed array will go here.

// Hack up the XML and put it into the array
foreach($structure as $s)
{
      if ($s["tag"] == "FOUND") {
           $found = $s['value'];
      }
}

return $found;
}

#
# build the API URL to call
#

$params = array(
      'api_key' => '[API KEY]',
      'method' => 'webpurify.live.check',
      'text' => 'test text'
);

$encoded_params = array();

foreach ($params as $k => $v){
     $encoded_params[] = urlencode($k).'='.urlencode($v);
}

#
# call the API and decode the response
#
$url = "http://www.webpurify.com/services/rest/?".implode('&', $encoded_params);

$rsp = file_get_contents($url);
$ar = ParseXML($rsp);

#
# output the response
#

if ($ar < 1){
     echo "No Profanity Found!";
}else{
     echo "Profanity!!";
}