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 7 of 7
  1. #1
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts

    Measuring the length of a gz string

    Does anyone have any suggestions as to whether, (and if so how), measuring the byte length of a gzencoded string is possible, without writing it to a flatfile and using filesize or suchlike. I'll be damned if I can figure/find a way to do it.


    Cheers.
    Last edited by MattF; 01-27-2010 at 08:19 PM. Reason: Edited to clarify the question.

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    The above?

    Did you have code to show us that you forgot to include?

  • #3
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by kbluhm View Post
    The above?

    Did you have code to show us that you forgot to include?
    Nope. No code. I was referring to the title line. I'll edit the first post to make that a bit less vague in meaning. It's just a simple gz encoded string I'm trying to find the size of. To use the example below:

    Code:
    $input = 'Some input here';
    $output = gzencode($input);
    how might one find the byte length of the $output string?

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    PHP Code:
    echo strlen(gzdecode($output)); 
    perhaps?
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #5
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by JAY6390 View Post
    PHP Code:
    echo strlen(gzdecode($output)); 
    perhaps?
    Nope. That don't work. Already tried that one and every other suggestion I've found so far. mbstrlen with encoding set to Latin, etc doesn't work either. It's to determine the filesize for a Content-Length: header, but every method I've tried so far comes nowhere near to what the browser reports as being the filesize.

  • #6
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    This is nowhere near tested, but would this work?
    PHP Code:
    ob_start();
    echo 
    $gz_string;
    $length ob_get_length();
    ob_end_clean(); 

  • Users who have thanked kbluhm for this post:

    MattF (01-28-2010)

  • #7
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by kbluhm View Post
    This is nowhere near tested, but would this work?
    PHP Code:
    ob_start();
    echo 
    $gz_string;
    $length ob_get_length();
    ob_end_clean(); 
    To perfection, it would appear. You're an absolute star. I've spent several days on this one and I got absolutely nowhere fast. Thanks ever so much.


  •  

    Posting Permissions

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