3v4l.org

run code in 300+ PHP versions simultaneously
<?php class OpenCalaisHandler { private $apiKey; private $apiUrl = 'http://api.opencalais.com/enlighten/rest/'; private $contentType = 'TEXT/RAW'; private $outputFormat = 'Application/JSON'; private $relTag = 'http://www.stefan-nieuwenhuis.nl'; private $calcRel = true; //calculate relevance score? private $enableMeta = false; //GenericRelations,SocialTags private $rdfAccess = false; //save doc in Calais repository? private $allowDist = false; //can data be distributed? private $allowSearch = false; //allow data to be searched? private $extId = 'Stefan_Nieuwenhuis'; private $submitter = 'Stefan Nieuwenhuis'; private $inputString = ''; function __construct($apiKey) { $this->apiKey = $apiKey; $this->SetupConnection; } private function GetInput() { return $this->inputString; } private function SetupConnection() { $postFields = 'licenseID='.urlencode($this->apiKey); $postFields .= '&paramsXML='.urlencode($this->CreateParamXml()); $postFields .= '&content='.urlencode($this->GetInput()); $cf = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->apiUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); curl_setopt($ch, CURLOPT_POST, 1); $response = curl_exec($cf); return $response; } private function CreateParamXml() { $xml = <<<XML <c:params xmlns:c="http://s.opencalais.com/1/pred/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <c:processingDirectives c:contentType="$this->contentType" c:enableMetadataType="$this->enableMeta" c:outputFormat="$this->outputFormat" c:docRDFaccesible="$this->rdfAccess" > </c:processingDirectives> <c:userDirectives c:allowDistribution="$this->allowDist" c:allowSearch="$this->allowSearch" c:externalID="$this->extId" c:submitter="$this->submitter"> </c:userDirectives> <c:externalMetadata> </c:externalMetadata> </c:params> XML; return $xml; } } $class = new OpenCalaisHandler('kx78mmny8st4qa8q5ry5uvv9'); ?>

preferences:
30.39 ms | 402 KiB | 5 Q