- i wanna to know how strtotime (php Date function) work?
- how Parse string Like "15 September 2012" to timeStamp
- is there any better algorithm?
my purpose is changing this function for Persian Language
my purpose is changing this function for Persian Language
You can browse the source code of PHP ( https://github.com/php/php-src) and search function to see its implementation.
UPDATE
Here is the algorithm of the function strtotime () https://github.com/php/php-src/blob/master/ext/date/php_date.c#L1324
Regards!.
The method that actually parses the string is in parse_date.re's scan()
method. There you will find all strtotime
keywords and their behaviors.
That library is included from https://github.com/derickr/timelib.
since strtotime accepts English input, I'd recommend taking the Persian input: "15 (SOMETHING_PERSIAN) 2012" and replace the required string (you need some RegExp and a switch statement, I guess) and make it "15 (SOMETHING_ENGLISH) 2012" and THEN send it to strtotime
i wanna to know how strtotime (php Date function) work?
Go here: https://github.com/php/php-src/blob/master/ext/date/lib/parse_date.c
Search for timelib_strtotime
.
forget about it, use php Intl extension. in future will be a part of php core.
<?php
// format
$format = datefmt_create('fa_IR@calendar=persian', IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'Asia/Tehran', IntlDateFormatter::TRADITIONAL, 'yyyy/MM/dd HH:mm');
// time in locale as you wish
var_dump(datefmt_format($format, time())); // '۱۳۹۱/۰۲/۰۴ ۱۹:۱۵'
support ICU project if you want to support Persian in i18n for all languages.