Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Yandex XML Position Checker Script v1.0a (c) Decker, decker(at)compkaluga.ru
- ----------------------------------------------------------------------------
- */
- function curl_file_get_contents($fp_url) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $fp_url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- $fp = curl_exec($ch);
- curl_close($ch);
- return $fp;
- }
- $our_domain = "compkaluga.ru";
- $keywords = 'создание сайтов калуга
- создание сайтов в калуге
- продвижение сайтов в калуге
- продвижение сайтов калуга
- seo оптимизация в калуге
- seo в калуге
- контекстная реклама в калуге
- купить сайт в калуге
- сайт-визитка калуга
- создание сайта визитки в калуге';
- $keywords = explode("\r\n",$keywords);
- $res = Array();
- echo '<h2 align="center">Наши позиции</h2>';
- echo '<table border="1" cellpadding="4" cellspacing="0">';
- foreach ($keywords as $keyword) {
- $params = array(
- 'user' => 'yandex_user', // логин
- 'key' => '00.0000000000000000000000000000000000000000', // ключ Яндекс.XML
- 'filter' => 'none',
- 'groupby' => 'attr=d.mode=deep.groups-on-page=100', // attr=<служебный атрибут>.mode=<тип группировки>.groups-on-page=<количество групп на одной странице>.docs-in-group=<количество документов в каждой группе>
- 'query' => urlencode($keyword),
- 'lr' => 6
- );
- $url = "http://xmlsearch.yandex.ru/xmlsearch" . '?' . urldecode(http_build_query($params));
- $fp = curl_file_get_contents($url); // для CURL
- // $fp = file_get_contents($url); // если CURL не установлен
- $xml = @simplexml_load_string($fp,'SimpleXMLElement', LIBXML_NOCDATA);
- $results = Array(); $i=0; $found = false; $found_index = "";
- foreach ($xml->response->results->grouping->group as $group) {
- $results[] = Array('domain' => trim($group->doc->domain), 'url' => trim($group->doc->url),'title' => $group->doc->title);
- if ($results[$i]['domain'] == $our_domain) { $found = true; $found_index = $i; }
- $i++;
- }
- $res[] = $results;
- echo '<tr>';
- if ($found) {
- echo '<td><a href="'.$results[$found_index]['url'].'">'.urldecode($params['query'])."</a></td><td>" . (($found) ? ($found_index+1) : ">100") ."</td>";
- $title = preg_replace("!<hlword>(.*?)</hlword>!si","<b>\\1</b>",$results[$found_index]['title']->asXML());
- $title = preg_replace("!<title>(.*?)</title>!si","\\1",$title);
- echo '<td>'.iconv("UTF-8","CP1251",$title).'</td>';
- }
- else {
- echo '<td>'.urldecode($params['query'])."</td><td>" . (($found) ? ($found_index+1) : ">100") ."</td>";
- echo '<td> </td>';
- }
- echo '</tr>';
- echo "\r\n";
- }
- echo '</table><p>';
- $i=0;
- foreach ($keywords as $keyword) {
- echo '<h2 align="center">'.$keyword.'</h2>';
- echo "\r\n";
- echo '<table border="1" cellpadding="4" cellspacing="0">';
- $j=0;
- foreach ($res[$i] as $r) {
- echo '<tr>';
- echo '<td><a href="'.$r['url'].'">'.$r['domain']."</a></td><td>" . intval($j+1) ."</td>";
- $title = preg_replace("!<hlword>(.*?)</hlword>!si","<b>\\1</b>",$r['title']->asXML());
- $title = preg_replace("!<title>(.*?)</title>!si","\\1",$title);
- echo '<td>'.iconv("UTF-8","CP1251",$title).'</td>';
- $j++;
- echo '</tr>';
- echo "\r\n";
- }
- $i++;
- echo '</table><p>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement