DarkPrince2005 Posted July 11, 2011 Share Posted July 11, 2011 I have a LONG string with multiple dates in, using preg_split I can split where the dates apear, but I want the dates to also appear, any ideas? <?php $chars = preg_split('@[\d][\d]-[\d][\d]-[\d][\d][\d][\d]@', $text); ?> Quote Link to comment https://forums.phpfreaks.com/topic/241680-preg_split/ Share on other sites More sharing options...
teynon Posted July 11, 2011 Share Posted July 11, 2011 What is the goal here? You could use preg_match_all and get all of the dates in an array. Posting all the code can help us figure out what you're trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/241680-preg_split/#findComment-1241280 Share on other sites More sharing options...
DarkPrince2005 Posted July 11, 2011 Author Share Posted July 11, 2011 What I'm basically trying to accomplish is get the string: "01-01-2011 Lorem ipsum dolar set 03-05-2011 lasret" to be displayed "01-01-2011 Lorem ipsum dolar set 03-05-2011 lasret" Quote Link to comment https://forums.phpfreaks.com/topic/241680-preg_split/#findComment-1241283 Share on other sites More sharing options...
teynon Posted July 11, 2011 Share Posted July 11, 2011 <?php $text = "01-01-2011 Lorem ipsum dolar set 03-05-2011 lasret"; if ($text=preg_replace("@([\d][\d]-[\d][\d]-[\d][\d][\d][\d])@", "<br />$1<br />", $text)) { echo $text; echo 'true'; } else { echo "false"; return FALSE; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/241680-preg_split/#findComment-1241284 Share on other sites More sharing options...
DarkPrince2005 Posted July 11, 2011 Author Share Posted July 11, 2011 How would I check for multiple date formats eg. dd/mm/yyyy, dd-mm-yyyy, yyyy-mm-dd, etc. Quote Link to comment https://forums.phpfreaks.com/topic/241680-preg_split/#findComment-1241285 Share on other sites More sharing options...
teynon Posted July 11, 2011 Share Posted July 11, 2011 create a preg patter for each logical date format and blend it in that statement with | (or) Quote Link to comment https://forums.phpfreaks.com/topic/241680-preg_split/#findComment-1241295 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.