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.Vevb.com/"><img src="http://www.Vevb.com/uploadfile/2012/1205/20121205112558940.jpg"></a><a href="http://www.baidu.com/"><img src="http://www.Vevb.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.Vevb.com/uploadfile/2012/1205/20121205112558940.jpg"
- [1] => src="http://www.Vevb.com/uploadfile/2012/1205/20121205112558940.jpg"
- )
- [1] => Array
- (
- [0] => src
- [1] => src
- )
- [2] => Array
- (
- [0] => "
- [1] => "
- )
- [3] => Array
- (
- [0] => http://www.Vevb.com/uploadfile/2012/1205/20121205112558940.jpg
- [1] => http://www.Vevb.com/uploadfile/2012/1205/20121205112558940.jpg
- )
- [4] => Array
- (
- [0] => jpg
- [1] => jpg
- )
- )
新闻热点
疑难解答