iBegins
 

Code chuyển chữ in hoa sang chữ thường PHP

convert the string to lowercase, calculate the string length, get the first letter of the string, convert the first letter to uppercase, get the rest of the string, return the string converted to sentence case.

Chuyển toàn bộ chữ in hoa thành chữ thường và viết hoa chữ cái đầu tiên trong câu văn. Dưới đây là đoạn mã PHP Function để thực hiện chuyển đổi.

function sentence_case( $string ) {
$string = mb_strtolower( $string, 'UTF-8' ); //convert the string to lowercase
$string_len = mb_strlen( $string, 'UTF-8' ); //calculate the string length
$first_letter = mb_substr( $string, 0, 1, 'UTF-8' ); //get the first letter of the string
$first_letter = mb_strtoupper( $first_letter, 'UTF-8' ); //convert the first letter to uppercase
$rest_of_string = mb_substr( $string, 1, $string_len, 'UTF-8' ); //get the rest of the string
return $first_letter . $rest_of_string; //return the string converted to sentence case
} 

Ngày 2 Tháng Tám, 2020 ( 1248 )

Tagged with: , ,

Bình luận bài viết

Đăng nhập để bình luận và xem các bình luận khác.