Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    mypointofview
    Guest

    Server configuration gives problem with am/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?
    Last edited by mypointofview; 07-21-2008 at 09:41 PM.

  • #2
    New Coder
    Join Date
    Jul 2008
    Posts
    91
    Thanks
    4
    Thanked 9 Times in 9 Posts
    what about posting the code? just the date function.

  • #3
    mypointofview
    Guest
    In top of page -- I "include" this from a project specific file:

    PHP Code:
    <?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 Code:
    <?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;
            }

    ?>
    Last edited by mypointofview; 07-23-2008 at 12:59 PM. Reason: should be "strtoupper" >> that makes am/pm **lowercase**

  • #4
    New Coder
    Join Date
    Jul 2008
    Posts
    91
    Thanks
    4
    Thanked 9 Times in 9 Posts
    strtolower(" &#37;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();

  • #5
    mypointofview
    Guest
    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".

  • #6
    New Coder
    Join Date
    Jul 2008
    Posts
    91
    Thanks
    4
    Thanked 9 Times in 9 Posts
    Well... try this instead:

    PHP Code:
    //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:

    PHP Code:
    //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
    Last edited by scoop_987; 07-22-2008 at 07:24 PM.

  • #7
    mypointofview
    Guest
    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 "&#37;" 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.
    Last edited by mypointofview; 08-08-2008 at 01:12 PM.

  • #8
    mypointofview
    Guest
    OK, this works now:

    Code:
    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
    Last edited by mypointofview; 08-08-2008 at 12:26 PM.

  • #9
    mypointofview
    Guest

    Working now

    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 Code:

    <?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;
    }
    ?>
    Last edited by mypointofview; 08-08-2008 at 01:58 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •