Home  >  Article  >  php教程  >  PHP code to extract the first picture on the page as a thumbnail

PHP code to extract the first picture on the page as a thumbnail

大家讲道理
大家讲道理Original
2016-11-09 14:30:231236browse

<?php
$p = &#39;/<img .*?src=[\&#39;|\"](.+?)[\&#39;|\"].*? alt="PHP code to extract the first picture on the page as a thumbnail" >/i&#39;;
preg_match_all($p,$str,$match);
print_r($match[1][0]);
?>
<img alt="PHP code to extract the first picture on the page as a thumbnail"http://usr.im/200x60?bg=3498DB&text=tool.lu" class="img" />
结果为:http://usr.im/200x60?bg=3498DB&text=tool.lu
  
<img alt="PHP code to extract the first picture on the page as a thumbnail"http://img.mukewang.com/user/55c877240001291602790279-80-80.jpg" class="img" />
结果为:http://img.mukewang.com/user/55c877240001291602790279-80-80.jpg


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn