开发者

Reliable strtotime() result for different languages

There was always a strange bug in Joomla when adding new article with back-end displayed with a language other than English (for me it's Russian). The field "Finish Publishing" started to be current date instead of "Never" equivalent in Russian.

For a site in php4 finally found that strtotime function returns different results for arbitrary words. For "Never" it always -1 and joomla relies on this result in the JDate implementation. But in other case it sometimes returns a valid date. For russian translation of Never (Никогда) it is the case, but also for single "N" it is the case, so if one decided to change the string to some other he or she would face the same issue.

So the code below

    <?php
      echo "Res:".strtotime("N")."<br>";
      echo "Res:".strtotime("Nev")."<br>";
      echo "Res:".strtotime("Neve")."<br>";
      echo "Res:".strtotime("Never")."<br>";
    ?>

Outputs:

    Res:1271120400
    Res:-1
    Res:-1
    Res:-1

So what are the solutions would be in this case? I would like not to write language-specific date.php handler, but to modify date method of JDate class, but what are language-neutral changes would be in orde开发者_Go百科r to detect invalid string.

Thank you


I would try a different aproach. Why don't you try just to add a new language variable $example="-1" to your language files and replace the existing variable ("Никогда" output) with $example so you can simply get the same functionallity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜