Home  >  Article  >  Backend Development  >  How to use php to determine whether there are pictures in an article

How to use php to determine whether there are pictures in an article

怪我咯
怪我咯Original
2017-07-05 10:13:361199browse

This article mainly introduces the method of PHP to determine whether there are pictures in the article. It is a very practical function. Friends who need it can refer to the

of this article. The PHP program is used to determine whether the article contains images. The main implementation idea is to use preg_match to check whether there is a matching " Stop talking nonsense, here is the main implementation code:

$url="http://XXXXX/article/012.html";
$content=file_get_contents($url); //读取文章页面源代码
if(preg_match("/<img.*>/",$content)){ //进行正则匹配判断是否有图片
  echo "检测到图片";
}else{
  echo "未发现图片";
}

The above is the detailed content of How to use php to determine whether there are pictures in an article. For more information, please follow other related articles on the PHP Chinese website!

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