strURL; $retCode = $this->CallNewsECS($url, 1); if ($retCode == true) { $this->DisplayNewsContent(); } } // Returns the response as a string or false on error function CallNewsECS($url, $timeout) { // Parse the URL into parameters for fsockopen $UrlArr = parse_url($url); $host = $UrlArr['host']; $port = (isset($UrlArr['port'])) ? $UrlArr['port'] : 80; $path = $UrlArr['path']; $query = (isset($UrlArr['query'])) ? '?' . $UrlArr['query'] : ''; $path .= $query; // Zero out the error response $errno = null; $errstr = ''; $this->getDataError = ''; // Open the connection to News Source $fp = @fsockopen($host, $port, $errno, $errstr, $timeout); // Failed to open the URL if (!is_resource($fp)) { $this->getDataError = "Fsockopen error number = $errno Details = $errstr"; return false; } // Send an HTTP GET header and Host header if (!(fwrite($fp, 'GET '. $path .' HTTP/1.0' . "\r\n". 'Host: ' . $host . "\r\n\r\n"))) { fclose($fp); $this->getDataError = "Fwrite error. Could not write GET and Host headers"; return false; } // Block on the socket port, waiting for response from News Source if (function_exists('socket_set_timeout')) { @socket_set_timeout($fp, $timeout); socket_set_blocking($fp, true); } // Get the HTTP response code from CNET $line = fgets($fp , 1024); if ($line == false) { fclose($fp); $this->getDataError = "Fgets error. Did not receive any data back from News Source"; return false; } // HTTP return code of 200 means success if (!(strstr($line, '200'))) { fclose($fp); $this->getDataError = "HTTP error. Did not receive 200 return code from News Source. Instead, received this: $line"; return false; } // Find blank line between header and data do { $line = fgets($fp , 1024); if ($line == false) { fclose($fp); $this->getDataError = "Fgets: did not receive enough data back from News Source"; return false; } if (strlen($line) < 3) { break; } } while (true); $xml=''; // Fetch the data from News Source while ($line = fread($fp, 8192)) { if ($line == false) { fclose($fp); $this->getDataError = "Fread: error reading data from News Source"; return false; } $xml .= $line; } fclose($fp); $this->NewsXML = $xml; return true; // echo '
'; // echo 'News Response:'; // echo $this->NewsXML; // echo ''; } function DisplayNewsContent() { $p = xml_parser_create(); xml_parse_into_struct($p, $this->NewsXML, $this->NewsArray, $index); xml_parser_free($p); /* echo '
'; echo "Index array\n"; print_r($index); echo ''; echo '
'; echo "\nVals array\n"; print_r($values); echo ''; */ $this->NewsHTML .= '