I have this string representing a date: "21 marzo 2017" and i want to convert it to unix timestamp.
echo strtotime('21 march 2017'); works because the month is in english.
echo strtotime('21 maggio 2017'); Doesn't work because the month is in italian.
How can i get the unix timestamp from that italian string?
Thank you.
You should first convert your months in english with str_replace
:
str_replace('marzo','march',"21 marzo 2017");
Then you can use echo strtotime('21 march 2017');
If you have to convert other date, consider using a function and a switch-case.
From the PHP docs on strtotime
: http://php.net/strtotime
strtotime — Parse about any English textual datetime description into a Unix timestamp
So the only way to achieve what you're asking is to translate your month to English. How you achieve that will depend on the context of your application.
If you only need to support one language you might be able to create a simple string replacement system for Italian to English months.
If you need a more robust translation option you might want to look at something like the Google Cloud Translation API: https://cloud.google.com/translate/docs/