
<?php
$SoImages = ‘~<img [^>]* />~’;
preg_match_all($SoImages,$post->post_content,$Images);
$PictureAmount=count($Images[0]);
for($i=0;$i<$PictureAmount;$i++){
echo ‘<a rel=”lightbox[03]”>’.$Images[0][$i].’ </a>’ ;
}
?>
从文章内容中将图片挑选出来,使用的部分代码如下:
<?php
$pc = $post->post_content;
$sp = ‘/<img.+src=[‘“]([^'”]+)[‘“].*>/i’;
preg_match_all( $sp, $pc, $aPics );
$np = count($aPics[0]);
if ( $np > 0 ) {
for ( $i=0; $i < $np ; $i++ ) {
echo ‘<img src=”‘.$aPics[1][$i].’” alt=”‘.$aPics[1][$i].'”/>’;
};
};
?>
人吐槽 | 人点赞 |
发表评论