您的位置:首页 > 编程语言 > PHP开发

【phpcms-v9】phpcms-v9中添加内容时自动提取缩略图

2012-12-06 15:02 369 查看
1.代码如下:

//自动提取摘要
if(isset($_POST['add_introduce']) && $systeminfo['description'] == '' && isset($modelinfo['content'])) {
$content = stripslashes($modelinfo['content']);
$introcude_length = intval($_POST['introcude_length']);
$systeminfo['description'] = str_cut(str_replace(array("\r\n","\t",'[page]','[/page]','“','”',' '), '', strip_tags($content)),$introcude_length);
$inputinfo['system']['description'] = $systeminfo['description'] = addslashes($systeminfo['description']);
}
//自动提取缩略图
if(isset($_POST['auto_thumb']) && $systeminfo['thumb'] == '' && isset($modelinfo['content'])) {
$content = $content ? $content : stripslashes($modelinfo['content']);
$auto_thumb_no = intval($_POST['auto_thumb_no'])-1;
if(preg_match_all("/(src)=([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|bmp|png))\\2/i", $content, $matches)) {
$systeminfo['thumb'] = $matches[3][$auto_thumb_no];
}
}

2.案例:
<?php
$str='<a href="http://www.zhen.com/"><img src="http://www.zhen.com/uploadfile/2012/1205/20121205112558940.jpg"></a><a href="http://www.baidu.com/"><img src="http://www.zhen.com/uploadfile/2012/1205/20121205112558940.jpg"></a>';
preg_match_all("/(src)=([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|bmp|png))\\2/i", $str, $out);
echo "<pre>";
print_r($out);
?>

3.结果:
<pre>Array
(
[0] => Array
(
[0] => src="http://www.zhen.com/uploadfile/2012/1205/20121205112558940.jpg"
[1] => src="http://www.zhen.com/uploadfile/2012/1205/20121205112558940.jpg"
)

[1] => Array
(
[0] => src
[1] => src
)

[2] => Array
(
[0] => "
[1] => "
)

[3] => Array
(
[0] => http://www.zhen.com/uploadfile/2012/1205/20121205112558940.jpg [1] => http://www.zhen.com/uploadfile/2012/1205/20121205112558940.jpg )

[4] => Array
(
[0] => jpg
[1] => jpg
)

)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐