SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have this:
    Code:
    $size = @filesize($path);
    $size = $size/1024;
    $size = // wich function?
    when $size = 0.2365489
    the output has to be this: 0.24

    wich function do I need?

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Two choices:

    1) Use printf() to format the number when it is printed out
    http://www.php.net/manual/en/function.printf.php

    printf( %.2f, $size );

    or

    2) use round() to actually round the value
    http://www.php.net/manual/en/function.round.php

    $size = round($size, 2);

  3. #3
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx, another question:

    my server time is now 7.27 in the morning
    at home it is now 00.27 in the moring,
    i tried to fix it like this:
    Code:
    gmdate("d M Y H:i",time() - 25200);
    But this doesn't work...

  4. #4
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you mean it doesn't work?
    It returns a string, so it should be:

    echo gmdate("d M Y H:i",time() - 25200);
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about:
    PHP Code:
    print date("d M Y H:i"mktime(date("H") - 7,0,0,date("m"),date("d"),date("Y"))); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddydoesphp's output: 02 Mar 2001 05:49 (here it is 0:49)
    SonNguyen' output: 02 Mar 2001 05:49 (here it is 0:49)

    Both codes works, but they have a wrong output



    oh, freakysid,

    your printf( %.2f, $size );
    gives the following error:
    Warning: printf(): too few arguments in /myhosts/www/pubhtmldir

    your $size = round($size, 2);
    gives the following error:
    Warning: Wrong parameter count for round() in /myhost/www/pubhtml/index.php on line 89


    eeeeehhhhhhh, I'm in trouble

  7. #7
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i don't know about time... but as for the rounding...

    PHP Code:
    $size round ($size3); 
    that should work... I just tried it!
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay use this for the rounding
    PHP Code:
    $size number_format($size2); 

    For the date offset

    Do you want to make your home time the same as the server time?

    PHP Code:
    print date("d M Y H:i"mktime(date("H") + 7,0,0,date("m"),date("d"),date("Y"))); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    he,he - I'm pretty ignorant about printf

    As for round() wrong number of parameters. My code was for php4. Are u using php3?

  10. #10
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freakysid, I'm sure I have PHP4 installed!
    so...
    I'll try your stuff tonight!

    And Freddy
    Do you want to make your home time the same as the server time?
    No, I just want to turn back server time 7 hours

  11. #11
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One thing, you called gmdate -> GMT date, so your call will return GMT-7 and not servertime -7

    use this:
    echo date("d M Y H:i",time() - 25200);
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  12. #12
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that works fine!
    I've got the solution for my first problem now now the second

    round a number off...

  13. #13
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm... You must be doing something different than everyone else, because I just did these two and they both work exactly as shown below.


    PHP Code:
    <?
    $num 
    3434.42635675367;
    print 
    round($num2);
    ?>
    prints 3434.43

    AND

    PHP Code:
    <?
    $num 
    3434.42635675367;
    print 
    number_format($num2);
    ?>
    prints 3,434.43
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  14. #14
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thnx thnx thnx, everything works fine now, except:

    this:
    PHP Code:
    $time = @date("d M Y H:i",time() - 25200filemtime($path)); 
    when I echo $time, there nothing printed...

  15. #15
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is with the three args for the date function, it only takes two, the format to disalpy the date and time source. YOu have an extra one in there, the filemtime(*) what purpose is to serve? try taking the @ off to see what error you are getting
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  16. #16
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, normally it's this:
    PHP Code:
    $time = @date("d M Y H:i"filemtime($path)); 
    This function works! I'm using this to get upload date of a file (php ftp prog)
    But I want this time offset

    So I tried this:
    PHP Code:
    $time = @date("d M Y H:i",time() - 25200filemtime($path)); 
    But this doesn't work...

    Oh, I tried to leave the "@", but it's the same, when i print the $time, it's a blank field...

  17. #17
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    From the manual

    int filemtime (string filename)

    Returns the time the file was last modified, or false in case of an error. The time is returned as a Unix timestamp
    So since filemtime() returns a unix timestamp you should be able to use for subtractubg 7 hours from it

    PHP Code:
    $time date("d M Y H:i"filemtime($path) - 25200); 
    BTW What is with your other post the links got sorted by date see my reply.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  18. #18
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For those on php3 the round function can be used to round a number to 2 decimal places as follows.

    PHP Code:
    $num 0.12345;
    $num $num*100//out put is 12.345
    $num=round($num); //rounds number to 12
    $num=$num/100//out put is 0.12 
    If you need 3 decimal places change the 100's to 1000's. It is crude but works on both php3 and php4.
    Marty H.

  19. #19
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Everything is all right now!!!
    Thank you very much!

    I'm using this now:
    for the date:
    PHP Code:
    $time date("d M Y H:i",filemtime($path) - 25200); 
    in stead of round(), i use this:
    PHP Code:
    printf ("%.2f",$size); 
    up to my next thread


Bookmarks

Posting Permissions

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