Improved example #3 (%e modifier on Windows) - Patch by simon at stienen dot name (bug #53558)

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@306482 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Kalle Sommer Nielsen 2010-12-20 02:00:39 +00:00
parent 8ff6a10616
commit 38b8faf180

View file

@ -460,17 +460,18 @@ echo "1/3/2005 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/3/2005")) . "\n
</para>
<para>
<example>
<title>Cross platform compatible example using the %e modifier</title>
<title>Cross platform compatible example using the <literal>%e</literal> modifier</title>
<programlisting role="php">
<![CDATA[
<?php
$format = '%e';
// Jan 1: results in: '%e%1%' (%%, e, %%, %e, %%)
$format = '%%e%%%e%%';
// Check for Windows and only attempt to replace
// the %e modifiers if they exists in the format
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' && strpos($format, '%e') !== false) {
$format = str_replace('%e', '%#d', $format);
// Check for Windows to find and replace the %e
// modifier correctly
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
$format = preg_replace('#(?<!%)((?:%%)*)%e#', '\1%#d', $format);
}
echo strftime($format);