PHP 字符串 strlen()函數
strlen()函數是PHP的預定義函數。愛掏網 - it200.com它用來查找字符串的長度或者返回包括所有空格和特殊字符在內的字符串的長度。愛掏網 - it200.com
strlen(string);
參數 | 描述 | 必需/可選 |
---|---|---|
string | 指定要檢查的字符串。愛掏網 - it200.com | 必需。愛掏網 - it200.com |
示例1
<?php
str = 'Javatpoint';
echo "Your String is:".str;
echo "<br>";
echo "By using 'strlen()' function:".strlen($str); // 10
?>
輸出:
Your String is:Javatpoint
By using 'strlen()' function:10
示例2
<?php
str = 'Java T point';
echo "Your String is:".str;
echo "<br>";
echo "By using 'strlen()' function:".strlen($str);
// output =12 [including whitespace]
?>
輸出:
Your String is:Java T point
By using 'strlen()' function:12
示例3
<?php
str = 'P H P';
echo "Your String is:".str;
echo "<br>";
echo "By using 'strlen()' function:".strlen($str);
// output =11 [including whitespace]
?>
輸出結果:
Your String is:P H P
By using 'strlen()' function:11
參考資料:
http://php.net/manual/en/function.strlen.php
另見:
- str_split() :用于將字符串拆分成數組。愛掏網 - it200.com
- str_word_count() :用于計算字符串中的單詞數。愛掏網 - it200.com
- strcasecmp() :用于比較兩個字符串。愛掏網 - it200.com
聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。