Answer the question
In order to leave comments, you need to log in
How to display and crop a piece of code from a site?
Hello.
Help, how to cut off all unnecessary from the existing code on the site and get the necessary information?
The website has the following code:
<div class="ForRead">
<div class="navigation">
<a href="/online-reading/comicsonline/batman2016vol3/batman2016vol3042" class="leftC"></a>
<select class="C" onchange="window.location='/online-reading/comicsonline/batman2016vol3/batman2016vol3043/'+this.value">
<option value="1" selected="">-1-</option><option value="2" >-2-</option><option value="3" >-3-</option><option value="4" >-4-</option><option value="5" >-5-</option><option value="6" >-6-</option><option value="7" >-7-</option><option value="8" >-8-</option><option value="9" >-9-</option><option value="10" >-10-</option><option value="11" >-11-</option><option value="12" >-12-</option><option value="13" >-13-</option><option value="14" >-14-</option><option value="15" >-15-</option><option value="16" >-16-</option><option value="17" >-17-</option><option value="18" >-18-</option><option value="19" >-19-</option><option value="20" >-20-</option>
</select>
<a href="/online-reading/comicsonline/batman2016vol3/batman2016vol3043/2" class="rightC"></a>
</div>
<a href="http://comicsonline.ru/1/batman2016vol3/043/1.png" rel="shadowbox"><b>Увеличить</b></a>
<a href="/online-reading/comicsonline/batman2016vol3/batman2016vol3043/2"><img src="http://comicsonline.ru/1/batman2016vol3/043/1.png?st=&e="
alt="Комиксы Онлайн - Бэтмен том 3 - # 43 - Страница №1 - Batman vol 3 - # 43"
title="Комиксы Онлайн - Бэтмен том 3 - # 43 - Страница №1 - Batman vol 3 - # 43" ></a>
</div>
http://comicsonline.ru/1/batman2016vol3/043/1.png?st=&e=
http://comicsonline.ru/1/batman2016vol3/043/1.png?st=&e=
20
<?
$text = file_get_contents("http://site.com/index.php");
$data = array();
preg_match("/<div class=\"navigation\">(.*)<\/div>/Uis", $text, $out);
print "$out[1]";
?>
Answer the question
In order to leave comments, you need to log in
Do not write regular expressions for HTML parsing, there are more convenient solutions for this, for example
https://github.com/Imangazaliev/DiDOM
https://github.com/paquettg/php-html-parser
You can use Zend\Dom\Query
use Zend\Dom\Query;
$dom = new Query($html);
$src = $dom->execute('img')->current()->getAttribute('src');
$opt = $dom->execute('select option[last()]')->current()->getAttribute('value');
echo $src . PHP_EOL . $opt;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question