PHP Gets the code example for the first picture of each article in the Web site,
<?php $temp =mt_rand (1,4); $pattern = "/<[img| Img].*?src=[\ ' |\ "] (. *? (?: [\.gif|\.jpg|\.png])) [\ ' |\ '].*? [\/]?>/]; $content = $article->content; Article content Preg_match_all ($pattern, $content, $matchContent); if (Isset ($matchContent [1][0])) { $temp = $matchContent [1][0];} else{ $temp = "images/random/$temp. jpg";//need to place 4 JPG files in the appropriate location with the name 1,2,3,4}
The above code by default calls the first picture of the article, when the article does not have a picture, random call theme style/images/random/under the 1.jpg, 2.jpg, 3.jpg, 4.jpg pictures. If you don't want to call a random picture, you can modify it:
<?php $pattern = "/<[img| Img].*?src=[\ ' |\ "] (. *? (?: [\.gif|\.jpg|\.png])) [\ ' |\ '].*? [\/]?>/]; $content = $article->content; Article content Preg_match_all ($pattern, $content, $matchContent); if (Isset ($matchContent [1][0])) { $temp = $matchContent [1][0];} else{ $temp = "./images/no-image.jpg";//place a JPG image named No-image in the appropriate location}
Call the first picture of the article, if the article does not have a picture to call the default picture no-image.jpg
http://www.bkjia.com/PHPjc/1133119.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133119.html techarticle PHP Gets the code example for the first picture of each article in the website, php $temp =mt_rand (1,4); $pattern = "/[img| Img].*src=[\ ' |\ "] (. * (: [\.gif|\.jpg|\.png])) [\ ' |\ '].*[\/]/'; $content = $arti ...