SchweppesAle Posted December 24, 2009 Share Posted December 24, 2009 I'm guessing that preg_match() can't find a match due to the slashes in image path. Here's a var_dump from each variable. Element 4 of bannerImages should be match, I'm not having any luck though. $bannerData vardump: array( { ["id"]=> string(2) "26" ["title"]=> string(7) "banner2" ["img_location"]=> string(59) "http://localhost/Joomla1.5/images/banners/iP4600_banner.jpg" ["expiration_date"]=> string(10) "2009-12-31" ["start_date"]=> string(10) "2009-12-22" ["destination"]=> string(20) "http://www.yahoo.com" ["published"]=> string(1) "1" ["locations"]=> string(1) "1" } /*yea, i need to fix that image path, i noticed*/ var_dump($bannerImages): array(10) { [0]=> string(41) "../images/banners/Bakers-banner_large.jpg" [1]=> string(45) "../images/banners/TheFalconBanner-PodCast.gif" [2]=> string(28) "../images/banners/banner.jpg" [3]=> string(40) "../images/banners/banners_mtd_728x90.gif" [4]=> string(35) "../images/banners/iP4600_banner.jpg" [5]=> string(28) "../images/banners/index.html" [6]=> string(32) "../images/banners/osmbanner1.png" [7]=> string(32) "../images/banners/osmbanner2.png" [8]=> string(35) "../images/banners/shop-ad-books.jpg" [9]=> string(29) "../images/banners/shop-ad.jpg" } It looks simple foreach($bannerImages as $banner) { if(preg_match("/$banner/",$bannerData['img_location'])) { echo '<option SELECTED>'.$banner.'</option>'; } else echo '<option>'.$banner.'</option>'; } Link to comment https://forums.phpfreaks.com/topic/186216-simple-regex/ Share on other sites More sharing options...
SchweppesAle Posted December 24, 2009 Author Share Posted December 24, 2009 oh man, I should have placed this in the REGEX forum. Sorry about that. Link to comment https://forums.phpfreaks.com/topic/186216-simple-regex/#findComment-983442 Share on other sites More sharing options...
trq Posted December 24, 2009 Share Posted December 24, 2009 Not sure why you need preg_match(). foreach($bannerImages as $banner) { echo "<option" . (($banner == $bannerData['img_location']) ? " selected='selected'" : "") . ">$banner</option>"; } Link to comment https://forums.phpfreaks.com/topic/186216-simple-regex/#findComment-983465 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.