【发布时间】:2014-03-25 17:30:44
【问题描述】:
array(4) { [109]=> array(11) { ["ID"]=> string(3) "109" ["name"]=> string(29) "unsplash_52cd96f512830_1.jpeg" ["path"]=> string(113) "/Users/framecero/Framecero_Clientes/MIMO/MAMP/fashionist/wp-content/uploads/2014/03/unsplash_52cd96f512830_1.jpeg" ["url"]=> string(97) "http://localhost:8888/fashionist/wp-content/uploads/2014/03/unsplash_52cd96f512830_1-150x150.jpeg" ["width"]=> int(150) ["height"]=> int(150) ["full_url"]=> string(89) "http://localhost:8888/fashionist/wp-content/uploads/2014/03/unsplash_52cd96f512830_1.jpeg" ["title"]=> string(24) "unsplash_52cd96f512830_1" ["caption"]=> string(0) "" ["description"]=> string(0) "" ["alt"]=> string(0) "" } [113]=> array(11) { ["ID"]=> string(3) "113" ["name"]=> string(29) "unsplash_52d65d1ebeeb2_1.jpeg" ["path"]=> string(113) "/Users/framecero/Framecero_Clientes/MIMO/MAMP/fashionist/wp-content/uploads/2014/03/unsplash_52d65d1ebeeb2_1.jpeg" ["url"]=> string(97) "http://localhost:8888/fashionist/wp-content/uploads/2014/03/unsplash_52d65d1ebeeb2_1-150x150.jpeg" ["width"]=> int(150) ["height"]=> int(150) ["full_url"]=> string(89) "http://localhost:8888/fashionist/wp-content/uploads/2014/03/unsplash_52d65d1ebeeb2_1.jpeg" ["title"]=> string(24) "unsplash_52d65d1ebeeb2_1" ["caption"]=> string(0) "" ["description"]=> string(0) "" ["alt"]=> string(0) "" } [132]=> array(11) { ["ID"]=> string(3) "132" ["name"]=> string(29) "unsplash_523ae1f5502d6_1.jpeg" ["path"]=> string(113) "/Users/framecero/Framecero_Clientes/MIMO/MAMP/fashionist/wp-content/uploads/2014/03/unsplash_523ae1f5502d6_1.jpeg" ["url"]=> string(97) "http://localhost:8888/fashionist/wp-content/uploads/2014/03/unsplash_523ae1f5502d6_1-150x150.jpeg" ["width"]=> int(150) ["height"]=> int(150) ["full_url"]=> string(89) "http://localhost:8888/fashionist/wp-content/uploads/2014/03/unsplash_523ae1f5502d6_1.jpeg" ["title"]=> string(24) "unsplash_523ae1f5502d6_1" ["caption"]=> string(0) "" ["description"]=> string(0) "" ["alt"]=> string(0) "" } [163]=> array(11) { ["ID"]=> string(3) "163" ["name"]=> string(12) "building.jpg" ["path"]=> string(96) "/Users/framecero/Framecero_Clientes/MIMO/MAMP/fashionist/wp-content/uploads/2014/03/building.jpg" ["url"]=> string(80) "http://localhost:8888/fashionist/wp-content/uploads/2014/03/building-150x150.jpg" ["width"]=> int(150) ["height"]=> int(150) ["full_url"]=> string(72) "http://localhost:8888/fashionist/wp-content/uploads/2014/03/building.jpg" ["title"]=> string(8) "building" ["caption"]=> string(0) "" ["description"]=> string(0) "" ["alt"]=> string(0) "" } }
我需要在 foreach 中获取 url,我正在使用此代码:
<?php global $post;$medias = rwmb_meta( 'mimo_imgadv', 'type=image_advanced' );?>
<?php } else {$medias = '';}; ?>
<?php if ($medias !== ''){ ?>
<div class="cn_wrapper flexslider" >
<ul id="allimg_id<?php the_Id(); ?>" class="format_images slides">
<?php foreach($medias as $media){
// check if string ends with image extension
if (preg_match('/(\.jpg|\.png|\.bmp)$/', $media['url'])) {
echo '<li class="selector">';
?>
<a class="mimo-link-overimage" href="<?php the_permalink(); ?> " >
<div class="mimo-image-hover"><i class="fa fa-file-o"></i></div>
<?php
echo '<img src="' . $media['url'] . '" alt=""/>';
echo '</a>';
echo '</li>';
// check if there is youtube.com in string
}
}
?>
</ul>
</div>
但它只给了我最后一个网址。
有人知道代码发生了什么吗?
【问题讨论】:
-
我实际看到的唯一网址以
"jpeg"结尾,这与您的正则表达式完全不匹配。 -
嗨,我终于解决了,问题是上面的代码正在运行:)
-
我也是你推荐的 'jpeg' 但没有它也能正常工作?¿?