1

I have big array fetched with diff strpos() and substr() :

$array[n] = ('Jan 23', 'From Jan 4 to Feb 1', 'Jul 5 to 10');

and I wish a process to convert it to:

$array[n] = ('2013-01-23','2013-01-04/2013-02-01','2013-07-05/2013-07-10);

Thanks for your help. I plan to use strpos() to get the date string into the array. after that, I plan to explode the date array, then perform a foreach($date as $index => $value), if I can cast it to string then it´s a date, and I could use two digits, for months match with monthly names. and then form the desired string.

Is there a better solution?

2
  • 1
    I think preg_replace is most inefficient way to do this. I think you should look for better method. Commented Jan 21, 2013 at 17:31
  • Have you considered what happends when a start date will be 25 December, and end date 1 January? There is no year given... Commented Jan 21, 2013 at 17:43

1 Answer 1

2

Why don't you use instead strtotime() function and date_format() function? It can be very difficult to handle all the possible formats with regular expressions and string parsing.

date('Y-m-d', strtotime('your_string'));
Sign up to request clarification or add additional context in comments.

1 Comment

Without any example code, this is more suited as a comment, and not an answer, especially as it is worded as a question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.