To find the size of a JSON file in PHP, we can make use of the filesize()
function, which returns the size of the file in bytes. We can use this function in combination with the file_get_contents()
function, which reads the entire contents of a file into a string.
Here's an example code snippet:
main.php232 chars9 lines
In the above code snippet, we first get the file size using the filesize()
function and store it in the $file_size
variable. We then read the contents of the file into a string using the file_get_contents()
function and store it in the $json_string
variable. We then get the size of this string using the strlen()
function and store it in the $json_size
variable.
Finally, we output both the file size and the JSON size using echo
.
gistlibby LogSnag