iT邦幫忙

0

PHP如何取得要儲存的字串大小

file_put_contents('test.html',$_POST['template_content']);

$_POST['template_content'] 我有辦法判斷這個變數存成檔案後大概的大小嗎?
在還未執行file_put_contents()前判斷

1 個回答

0
通靈亡
iT邦新手 3 級 ‧ 2020-05-21 12:34:03
mb_strlen($_POST['template_content'], '8bit');

https://www.php.net/manual/en/function.mb-strlen.php

下面有一個留言有提到:

If you need length of string in bytes (strlen cannot be trusted anymore because of mbstring.func_overload) you should use mb_strlen($string, '8bit'); .
It's the fastest way (still a way slower than strlen, though) to determine byte length of string. Other single byte character sets (ASCII, ISO-8859-1, ...) are several times slower than 8bit.

豬豬人 iT邦新手 5 級 ‧ 2020-05-21 13:15:07 檢舉

謝謝 我試試看

我要發表回答

立即登入回答