Home  >  Article  >  php教程  >  PHP获取文章第一张图片做为缩略图 - 开源中国社区

PHP获取文章第一张图片做为缩略图 - 开源中国社区

PHP中文网
PHP中文网Original
2016-05-20 12:56:32889browse

跳至

	/**
	 * 获取文章第一张图片做为缩略图
	 * @param $content
	 * @return bool|string
	 */
	private static function thumb($content){
		$content = stripslashes($content);
		if(preg_match_all("/(src)=([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|bmp|png))\\2/i", $content, $matches)) {
			$str = $matches[3][0];
			$str = substr($str, 6);
			if (preg_match('/upload/', $str)) {
				return $str;
			}
		}
		return '';
	}

                   

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