$type = urlencode($_GET['type']); if (filter_var($_GET['url'], FILTER_VALIDATE_URL)) { if ($type == 'stumbleupon') { $content = parse("http://www.stumbleupon.com/services/1.01/badge.getinfo?url={$url}"); $result = json_decode($content); if (isset($result->result->views)) { $json['count'] = $result->result->views; } } if ($type == 'googlePlus') { //source http://www.helmutgranda.com/2011/11/01/get-a-url-google-count-via-php/ $content = file_get_contents("https://plusone.google.com/u/0/_/+1/fastbutton?url=" . urlencode($_GET['url']) . "&count=true"); $doc = new DOMdocument(); libxml_use_internal_errors(true); $doc->loadHTML($content); $doc->saveHTML(); $num = $doc->getElementById('aggregateCount')->textContent; $json['count'] = $num ? $num : '0'; } } echo str_replace('\\/', '/', json_encode($json)); function parse($encUrl) { $options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_USERAGENT => 'sharrre', CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_TIMEOUT => 10, CURLOPT_MAXREDIRS => 3, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => false); $ch = curl_init(); $options[CURLOPT_URL] = $encUrl; curl_setopt_array($ch, $options); $content = curl_exec($ch); $err = curl_errno($ch); $errmsg = curl_error($ch); curl_close($ch);
<?php libxml_use_internal_errors(true); header("Content-Type: text/plain; charset=utf-8"); $str = <<<EOF <html> \t<head> \t\t<meta http-equiv='Content-Type' content='text/html; charset=utf-8'> \t</head> \t<body> \t\t<p>Toto vas à la <b>plage</b>.</p> \t</body></div></b> </html> EOF; libxml_use_internal_errors(false); $str = strip_tags($str, "<meta><b><i>"); $doc = new DOMdocument(); $doc->loadHTML($str); $str = $doc->saveHTML(); echo $str;