Hello, dear experts.

I ask for your help. I wrote using simple html dom a small parser of pictures. I pull a cycle from there the pictures themselves and the names of the links to them. Using the substr function, I shorten the names of links to 13 characters. I save the pictures in the images folder. I also need to change the name of the pictures to the names of shortened links.

Here is the code itself: include_once ('simple_html_dom.php');

$html = file_get_html('http://site.ru/items/search?utf8='); // Find all links foreach($html->find('div.item_text a') as $element) { $a = $element->href; $link = explode("/", $a); $url = end($link); echo substr($url, 0, 13). '<br />'; } // Find all images foreach($html->find('div.item_img img') as $element) { echo '<img src="'.$element->src.'">' . '<br />'; $src = $element->src; $arr = explode("/", $src); $name = end($arr); file_put_contents("images/$name", file_get_contents($src)); } 

Really looking forward to your help or hints.

Added by:

The first cycle gives the names of shortened links:

 4602547000701 4602547000015 4601728012885 

The second cycle gives the images themselves:

 <img src="http://site.ru/system/images/tovar/small/151f938d3d16fea22f0dc7f73350e8ae.jpeg"> <img src="http://site.ru/system/images/tovar/small/1a610cb1bfecc513f5cc86c8898567b3.jpeg"> <img src="http://site.ru/noimage.gif"> 

I also need to rename the names of the pictures in the title links. T. e. On the example of the first image: It was the name of the image - 151f938d3d16fea22f0dc7f73350e8ae.jpeg , became 4602547000701.jpeg

  • What to change? An example is possible, entry and exit is desirable. - Manitikyl
  • Here it is :-) <code> include_once ('simple_html_dom.php'); $ html = file_get_html (' site.ru/items/search?utf8=' ); // Find all links foreach ($ html-> find ('div.item_text a') as $ element) {$ a = $ element-> href; $ link = explode ("/", $ a); $ url = end ($ link); echo substr ($ url, 0, 13). ''; } // Find all images foreach ($ html-> find ('div.item_img img') as $ element) {echo '<img src = "'. $ Element-> src. '">'. ''; $ src = $ element-> src; $ arr = explode ("/", $ src); $ name = end ($ arr); file_put_contents ("images / $ name", file_get_contents ($ src)); } </ code> - Kirill Seleznev

0