<html> <head> <title>Parser</title> </head> <META http-equiv="Content-Type" content="text/html; charset=utf-8"> <style type="text/css"> .urls a:link { FONT-SIZE:10pt; color: #008040; text-decoration:none; font-weight: bold; font-family: Verdana, Arial;} a:visited { FONT-SIZE:10pt; color: #008040; text-decoration:none; font-weight: bold; font-family: Verdana, Arial;} a:active { FONT-SIZE:10pt; color: #000000; text-decoration:none; font-weight: bold; font-family: Verdana, Arial;} a:hover { FONT-SIZE:10pt; color: #000000; text-decoration:none; font-weight: bold; font-family: Verdana, Arial; } .urls { position: absolute; top: 20%; width: 700px; } </style> <body> <?php // запрос $zapros = "Секс"; if ( isset($zapros) ) { // Урл $target = "http://uk.wikipedia.org/w/index.php"; // инициализация cURL $ch = curl_init($target); // получать заголовки curl_setopt ($ch, CURLOPT_HEADER, 1); // если проверяеться HTTP User-agent curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3'); // использовать метод POST curl_setopt ($ch, CURLOPT_POST, 1); // передаем даные curl_setopt ($ch, CURLOPT_POSTFIELDS, '?title=Спеціальна%3ASearch&search='.$zapros.'&fulltext=Пошук'); // вернуть результат curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); // делаем запрос curl_exec ($ch); // Берем результат $result = curl_multi_getcontent ($ch); // Парсимо с помощю регулярки // масив $var[0] будет помещать результаты полного совпадения с шаблоном preg_match_all("#(<a href=)(.*)(<span class='searchmatch'>)(.*)(</a>)#", $result, $var); // выводим результаты foreach ($var[0] as $value) { if ( !preg_match("#http://#", $value) ) { $value = preg_replace("#/wiki/#", "http://uk.wikipedia.org/wiki/", $value); } $urls[] = $value; } //Выводим результати echo '<div align="center" class="urls">'; for ($i=0; $i<15; $i++) { echo ''.$urls[$i].'     '; } echo '</div>'; } ?> </body> </html>