Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7087827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:43:19+00:00 2026-05-28T07:43:19+00:00

I am trying to get the number bytes in a PHP string. I seem

  • 0

I am trying to get the number bytes in a PHP string. I seem to be running into a problem trying to send raw HTTP requests (PROPFIND, REPORT), and getting the proper length of the content. From which point, following the headers, do I start counting the content? And at which point, do I stop?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:43:20+00:00Added an answer on May 28, 2026 at 7:43 am

    You count the complete content, starting after the two linebreaks that delimit the header section:

    $contentlength_bytes = strlen(strstr($http, "\r\n\r\n")) - 4;
    

    If you’re doing it that way already i guess you might have run into problems with encoding…

    When your content has multibyte characters, using strlen() to return it’s bytelength might not work correctly as multibyte characters might get interpreted as one byte under certain system configurations (see edit below – and comments for that part).

    This will give you the correct bytelength of any content-string you feed it under any system configuration:

    $contentlength_bytes = mb_strlen(strstr($http, "\r\n\r\n"), 'latin1') - 4;
    

    Edit:
    As Jon pointed out in the comments, this is not always needed as strlen() will return the correct bytecount of a string in most circumstances.

    I just added this method of measuring as on multibyte systems and under certain circumstances (for example mbstring.func_overload set to 2) strlen() is not safe to use against binary strings.

    The above method is the only known (to me) way to completely binary safe calculate the byte-length of a given string. And i tripped over this a couple of times already..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find a way to get the number of bytes transferred from
In a PowerShell script I am trying to get the number of page faults
I've struggled with this all day, I am trying to get a random number
I'm trying to get the integer value of The number selected of the item.
I am trying to get my first button to update a display number in
I'm trying to find a way to get the total number of child nodes
I'm trying to do project Euler number 219 but am failing to get a
I'm trying to parse phone number with regex. Exactly I want to get a
I am trying to wrap up some data from an array of BYTES into
I'm trying to read a number of performance counters from a running .NET 4

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.