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); ?> 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. 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" 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; } ?> 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. 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) Link to comment https://forums.phpfreaks.com/topic/241680-preg_split/#findComment-1241295 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.