PHP程式,用於查詢字串中的字元數
要查詢字串中的字元數,PHP 程式碼如下所示 -
示例
<?php
$my_string = "Hi there, this is a sample ";
$len = mb_strlen($my_string);
print_r("The number of characters in the string is ");
echo $len;
?>輸出
The number of characters in the string is 27
上面定義了一個字串,它在中間有多於所需的空格 -
$my_string = "Hi there, this is a sample ";
接下來,使用“strlen”函式計算字串的長度。此長度被分配給一個變數。這將提供字串中存在的字元,包括空格 -
$len = mb_strlen($my_string);
然後將計算出的長度列印在螢幕上 -
print_r("The number of characters in the string is ");
echo $len;
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP