через file_get_contents достаю содержимое сайта
и вставляю в переменную $html
Как теперь оттуда вытащить все значения name из всех инпутов? Понимаю, что это нужно делать как-то регуляркой, но не знаю как.
Цитата (Dezigo @ 6.01.2015 - 19:50) |
Та да! http://htmlparsing.com/php.html http://simplehtmldom.sourceforge.net/ http://php.net/manual/en/domdocument.loadhtml.php |
<?php
# Use the Curl extension to query Google and get back a page of results
$url = "http://www.google.com";
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$html = curl_exec($ch);
curl_close($ch);
# Create a DOM parser object
$dom = new DOMDocument();
# Parse the HTML from Google.
# The @ before the method call suppresses any warnings that
# loadHTML might throw because of invalid HTML in the page.
@$dom->loadHTML($html);
# Iterate over all the <a> tags
foreach($dom->getElementsByTagName('a') as $link) {
# Show the <a href>
echo $link->getAttribute('href');
echo "<br />";
}
?>