PHP strlen関数で文字列のバイト数を取得する

環境
PHP 8.1.2
Ubuntu 22.04.1 LTS

構文
$変数名 = strlen(対象の文字列);
文字列(string)のバイト数を取得するには、strlen()を使います。

使用例

<?php
// Your code here!
$text = "Hello,World";
$text2 = "こんにちは、日本";

$resA = strlen($text);
$resB = strlen($text2);

echo "textは、", $resA , "バイト", "\n";
echo "text2は、", $resB , "バイト";
?>

実行結果
textは、11バイト
text2は、24バイト

PHP

Posted by arkgame