galayman Posted November 30, 2007 Share Posted November 30, 2007 Hi All, i have this array $ary = array( "Today date is 1, our breakfast is 2 eggs and salad", "Today date is 13, our breakfast is 3 breads and beff", "Today date is 18, our breakfast is 2 toasts with egg", "Today date is 21, our breakfast is 5 wafels with honey", "Today date is 30, our breakfast is a bowl of sereal" ); i need to search and match the date (that i have bolded it) and then compare it to today date using this fuction date("j"); to find the date in the string i'm using this regex ([1-3][0-9]?)(?=, our) i have try everything but i cannot solve it so in the end, if today date is 18 i want to display only this string Today date is 18, our breakfast is 2 toasts with egg can i do this? Thank You , Best Regards Quote Link to comment Share on other sites More sharing options...
Stooney Posted November 30, 2007 Share Posted November 30, 2007 try using the stristr() function to search for 'is $today' where $today is the result of date("j"). I use the 'is' so you dont get results pertaining to the number of eggs and whatnot. Quote Link to comment Share on other sites More sharing options...
marcus Posted November 30, 2007 Share Posted November 30, 2007 You can try this. <?php $ary = array( "Today date is 1, our breakfast is 2 eggs and salad", "Today date is 13, our breakfast is 3 breads and beff", "Today date is 18, our breakfast is 2 toasts with egg", "Today date is 21, our breakfast is 5 wafels with honey", "Today date is 30, our breakfast is a bowl of sereal" ); $date = date("j"); foreach($ary AS $ara){ $ex = explode(" ", $ara); $ex = str_replace(",", NULL, $ex); if($ex[3] == $date){ $what = $ara; } } echo $what; ?> tested to some extent. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 30, 2007 Share Posted November 30, 2007 Can you change your array? If you can change it to: <?php $ary = array(1 => '2 eggs and salad', 13 => '3 breads and beff', 18 => '2 toasts with egg', 21 => '5 wafels with honey', 31 => 'a bowl of cereal'); ?> The the solution is very easy. <?php $date = date('j'); echo 'Today is ' . $date. ', our breakfast is ' . $ary($j); ?> Ken Quote Link to comment Share on other sites More sharing options...
galayman Posted November 30, 2007 Author Share Posted November 30, 2007 waw! phpfreaks guru is the best! Thank you, i love php and i love everyone here too! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.