mypointofview 07-21-2008, 09:26 PM Hi, I am experiencing a problem with my server configuration which outputs the time stamp for a modified page with a faulty am/pm symbol: "pm" displays as "P".
Here's my test page: http://tinyurl.com/5t6pw9
The test page shows the same php code on 3 different servers, running 5.14, 5.16 and 5.22. Only server with 5.16 displays correctly - so it's not a PHP bug. The server that shows am/pm correctly is at Webhero.com. The other servers are here on two of my Macintosh computers. I've provided links to the phpconfig files.
What must I change in my configuration?
Thanks in advance.
PS: If you check out the test page and try to reproduce it, you will see that for the am/pm display I needed to use strtoupper in order to display it in lowercase. Is this weird or what?
scoop_987 07-21-2008, 09:50 PM what about posting the code? just the date function.
mypointofview 07-21-2008, 10:04 PM In top of page -- I "include" this from a project specific file:
<?php
$language='en'; // tokens are 'en' 'fr' 'de'
$timezone='la'; // tokens are 'la' 'ny' 'paris' 'athens'
?>
The following to display file modification or first upload date and time:
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
if ($timezone == 'la') { $timezonelong = 'America/Los_Angeles'; $location = 'Los Angeles'; }
elseif ($timezone == 'ny') { $timezonelong = 'America/New_York'; $location = 'New York'; }
elseif ($timezone == 'paris') { $timezonelong = 'Europe/Paris'; $location = 'Paris'; }
elseif ($timezone == 'athens') { $timezonelong = 'Europe/Athens'; $location = 'Athens'; }
else { $timezonelong = 'UTC'; $location = 'UTC'; }
date_default_timezone_set($timezonelong);
if ($language == 'de') {
setlocale(LC_ALL, 'de_DE.utf-8'); echo "Letzte Änderung am " .strftime("%A dem %e. %B %Y um %R Uhr, ",filemtime($pfile)) .$location;
}
elseif ($language == 'fr') {
setlocale(LC_ALL, 'fr_FR.utf-8'); echo "Dernière modification le " .strftime("%A %e %B %Y à %R, ",filemtime($pfile)) .$location;
}
else {
setlocale(LC_ALL, 'en_US'); echo "Last modified " .strftime("%A, %B %e, %Y at %l:%M" .strtoupper(" %p, "),filemtime($pfile)) .$location;
}
?>
scoop_987 07-21-2008, 10:34 PM strtolower(" %p, ") ??
its always lower, and thats where the problem lies (i think), not that you have strtolower... but im not one for using strftime, id rather use date();
mypointofview 07-22-2008, 02:10 AM Sorry, I had a mistake in the php code: it must be strtoupper (I corrected the code in my post further up). Only then the am/pm is lowercase. if I'd use strtolower it would be in upper case. I just checked again.
Test it please and verify yourself. It must be a bug in PHP.
Now, since there's a workaround for this (thinking inverse) -- does anybody know where I can fix my server configuration to display am/pm to begin with? Currently on my Macintosh servers it's just "P" instead of "pm".
scoop_987 07-22-2008, 07:14 PM Well... try this instead:
//Since ive added the date function with the "A", it should always say AM or PM in upper
echo "Last modified " .date("l, F d, Y") . " at " . date("h:i A, ") . filemtime($pfile)) .$location;
If that doesnt work then you have some form of trim later on in the script
and if you want to modify it without using the code above try:
//A little more work but should work on Mac, *nix, and windows
$AMPM = strftime(strtoupper(" %p, "));
if($AMPM == "P"){
$AMPM = "PM";
}elseif($AMPM = "A"){
$AMPM = "AM";
}
echo "Last modified " .strftime("%A, %B %e, %Y at %l:%M") .$AMPM." ".filemtime($pfile)) .$location;
mypointofview 08-08-2008, 11:48 AM Scoop, a quick feedback: This is a step in the right direction and AM / PM shows now (the output is at least the same on my own private server as on my professional host. I'm wondering about those "%" characters which I used. Why are they there? I'm asking because I followed the PHP directions from the official site. I assume it's because I used "strftime" and you used "date"
I guess the main question is: what's better -- "date" or "strftime" ? I assume that the language set locale won't work with "date" ??
The other part of your code I have not tried yet.
mypointofview 08-08-2008, 12:20 PM OK, this works now:
echo "Last modified " .date("l, F j, Y") . " at " . date("g:i a, " ,filemtime($pfile)) .$location;
Output: Last modified Friday, August 8, 2008 at 3:39 am, Los Angeles
:)
http://us.php.net/date -- http://us.php.net/manual/en/function.strftime.php
mypointofview 08-08-2008, 01:52 PM In summary I had to change the code for the english am/pm style date, but also for the french date -- on my Mac the french day was capitalized (not so on my web hosting provider). See workaround in the code below. Works great now :) PS: the last code part is needed to display the french characters properly when making all lower case.
<?php
$timezone ='paris'; // change between 'la' 'ny' 'paris' 'athens'
$language ='fr'; // en = english, fr = french, de = german
?>
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
if ($timezone == 'la') { $timezonelong = 'America/Los_Angeles'; $location = 'Los Angeles'; }
elseif ($timezone == 'ny') { $timezonelong = 'America/New_York'; $location = 'New York'; }
elseif ($timezone == 'paris') { $timezonelong = 'Europe/Paris'; $location = 'Paris'; }
elseif ($timezone == 'athens') { $timezonelong = 'Europe/Athens'; $location = 'Athens'; }
else { $timezonelong = 'UTC'; $location = 'UTC'; }
date_default_timezone_set($timezonelong);
if ($language == 'de') {
setlocale(LC_ALL, 'de_DE.utf-8'); echo "Letzte Änderung am " .strftime("%A dem %e. %B %Y um %R Uhr, ",filemtime($pfile)) .$location;
}
elseif ($language == 'fr') {
setlocale(LC_ALL, 'fr_FR.utf-8'); echo "Dernière modification le " .strtolower_utf8(strftime("%A %e %B %Y à %R, ",filemtime($pfile))) .$location;
}
else {
setlocale(LC_ALL, 'en_US'); echo "Last modified " .date("l, F j, Y") . " at " . date("g:i a, ",filemtime($pfile)) .$location;
}
?>
<?php
function strtolower_utf8($inputString) {
$outputString = utf8_decode($inputString);
$outputString = strtolower($outputString);
$outputString = utf8_encode($outputString);
return $outputString;
}
?>
|
|