shz_furion
پنج شنبه 26 دی 1392, 18:39 عصر
سلام.میخواستم سیستمی رو بنویسم که باهاش اطلاعات رو از w3c دریافت کنه.
این کد رو پیدا کردم اما نمیدونم چطور خروجی ازش بگیرم.لطفا کمکم کنید.
<?php
class Validation {
private $domain;
private $htmlValidator = 'http://validator.w3.org/check?uri=%s';
public function __construct($domain) {
$this -> domain = $domain;
}
public function w3cHTML() {
$url = sprintf($this -> htmlValidator, 'http%3A%2F%2F'.$this -> domain);
return $this -> request($url);
}
private function request($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1090.0 Safari/536.6');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$buffer = curl_exec($ch);
$curl_info = curl_getinfo($ch);
if(curl_errno($ch)) {
return array(
'status' => '-',
'errors' => '-',
'warnings' => '-',
);
}
curl_close($ch);
$header_size = $curl_info['header_size'];
$headers = $this -> getHeaders(mb_substr($buffer, 0, $header_size));
return array(
'status' => isset($headers['X-W3C-Validator-Status']) ? mb_strtolower($headers['X-W3C-Validator-Status']) == 'valid' : false,
'errors' => isset($headers['X-W3C-Validator-Errors']) ? (int) $headers['X-W3C-Validator-Errors'] : 0,
'warnings' => isset($headers['X-W3C-Validator-Warnings']) ? (int) $headers['X-W3C-Validator-Warnings'] : 0,
);
}
private function getHeaders($response) {
$headers = array();
$header_text = substr($response, 0, strpos($response, "\r\n\r\n"));
foreach (explode("\r\n", $header_text) as $i => $line)
if ($i === 0)
$headers['Http Code'] = $line;
else {
list ($key, $value) = explode(': ', $line);
$headers[$key] = $value;
}
return $headers;
}
}
این کد رو پیدا کردم اما نمیدونم چطور خروجی ازش بگیرم.لطفا کمکم کنید.
<?php
class Validation {
private $domain;
private $htmlValidator = 'http://validator.w3.org/check?uri=%s';
public function __construct($domain) {
$this -> domain = $domain;
}
public function w3cHTML() {
$url = sprintf($this -> htmlValidator, 'http%3A%2F%2F'.$this -> domain);
return $this -> request($url);
}
private function request($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1090.0 Safari/536.6');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$buffer = curl_exec($ch);
$curl_info = curl_getinfo($ch);
if(curl_errno($ch)) {
return array(
'status' => '-',
'errors' => '-',
'warnings' => '-',
);
}
curl_close($ch);
$header_size = $curl_info['header_size'];
$headers = $this -> getHeaders(mb_substr($buffer, 0, $header_size));
return array(
'status' => isset($headers['X-W3C-Validator-Status']) ? mb_strtolower($headers['X-W3C-Validator-Status']) == 'valid' : false,
'errors' => isset($headers['X-W3C-Validator-Errors']) ? (int) $headers['X-W3C-Validator-Errors'] : 0,
'warnings' => isset($headers['X-W3C-Validator-Warnings']) ? (int) $headers['X-W3C-Validator-Warnings'] : 0,
);
}
private function getHeaders($response) {
$headers = array();
$header_text = substr($response, 0, strpos($response, "\r\n\r\n"));
foreach (explode("\r\n", $header_text) as $i => $line)
if ($i === 0)
$headers['Http Code'] = $line;
else {
list ($key, $value) = explode(': ', $line);
$headers[$key] = $value;
}
return $headers;
}
}