❮ Tham chiếu chuỗi PHP
Thí dụ
Chuyển đổi ký tự đầu tiên của mỗi từ thành chữ hoa
echo ucwords["Xin chào thế giới"];
?>
Định nghĩa và cách sử dụng
Hàm ucwords[] chuyển ký tự đầu tiên của mỗi từ trong chuỗi thành chữ hoa
Ghi chú. Hàm này an toàn nhị phân
chức năng liên quan
- ucfirst[] - chuyển ký tự đầu tiên của chuỗi thành chữ hoa
- lcfirst[] - chuyển ký tự đầu tiên của chuỗi thành chữ thường
- strtoupper[] - chuyển đổi một chuỗi thành chữ hoa
- strtolower[] - chuyển đổi một chuỗi thành chữ thường
cú pháp
ucwords[chuỗi, dấu phân cách]
Giá trị tham số
Tham sốChuỗi mô tảBắt buộc. Chỉ định chuỗi để convertdelimitersOptional. Chỉ định ký tự tách từchi tiết kỹ thuật
Giá trị trả về. Trả về phiên bản stringPHP đã chuyển đổi. 4+Nhật ký thay đổi. PHP5. 4 - Đã thêm tham số dấu phân cáchThêm ví dụ
Thí dụ
Chuyển đổi ký tự đầu tiên của mỗi từ thành chữ hoa, có thêm dấu tách từ tùy chỉnh
echo ucwords["Xin chào. thế giới", ". "];
?>
Nếu bạn cần viết hoa ký tự đầu tiên của mỗi từ trong một chuỗi trong PHP, bạn có thể sử dụng hàm ucwords[]. Hàm này lấy một chuỗi làm đối số và trả về một chuỗi mới với ký tự đầu tiên của mỗi từ trong chuỗi ban đầu được viết hoa
Sao chép mã
đầu ra
Hello World
Để chuyển đổi chữ cái đầu tiên của mỗi từ trong Chuỗi thành chữ hoa
- Xác định một chuỗi có chứa một số từ
- Truyền chuỗi cho hàm ucwords[] sẽ trả về chuỗi với mỗi từ có ký tự đầu tiên là chữ hoa
- in chuỗi
cú pháp
ucwords[$str]
PHP >> Chuỗi >> Chữ hoa-ký tự đầu tiên của mỗi từ
Câu hỏi
Làm cách nào để bạn viết hoa ký tự đầu tiên của mỗi từ trong một chuỗi bằng PHP?Câu trả lời
Sử dụng hàm PHP ucwords[]Đây là một ví dụ PHP cho thấy cách viết hoa ký tự đầu tiên của mỗi từ trong một chuỗi
Nguồn. [thí dụ. php]
đầu ra
$ php example.php The Cat In The Hat
Người giới thiệu
// C++ program to remove the first
5_______5_______69// C++ program to remove the first
83// C++ program to remove the first
64 // C++ program to remove the first
85// C++ program to remove the first
22// C++ program to remove the first
87// C++ program to remove the first
88// C++ program to remove the first
89// C++ program to remove the first
90 // C++ program to remove the first
22// C++ program to remove the first
92// C++ program to remove the first
83 // C++ program to remove the first
3// C++ program to remove the first
4
std;
9 string FirstAndLast[string str]
0
// and last character of each word in a string.
01
#include
3 // and last character of each word in a string.
03// C++ program to remove the first
64_______5_______64 // and last character of each word in a string.
06 // C++ program to remove the first
87
// and last character of each word in a string.
10_______5_______64 string FirstAndLast[string str]
8// C++ program to remove the first
4
// and last character of each word in a string.
16_______25_______17
// and last character of each word in a string.
16_______25_______20
// and last character of each word in a string.
21
C#
// and last character of each word in a string.
22
// and last character of each word in a string.
using
// and last character of each word in a string.
25
4 // and last character of each word in a string.
27
{
7
8
{
// C++ program to remove the first
5_______5_______02
// C++ program to remove the first
5_______25_______37#include
5// C++ program to remove the first
06
// C++ program to remove the first
5_______5_______08
// C++ program to remove the first
5_______5_______10_______5_______8// C++ program to remove the first
4
// C++ program to remove the first
5_______5_______14
// C++ program to remove the first
5_______5_______16
// C++ program to remove the first
5_______25_______51 // and last character of each word in a string.
52// C++ program to remove the first
79 // and last character of each word in a string.
54
// C++ program to remove the first
5_______52_______
#include
9// and last character of each word in a string.
58// C++ program to remove the first
3_______5_______4
// C++ program to remove the first
5_______86_______5
// C++ program to remove the first
5_______22_______9 string FirstAndLast[string str]
0
namespace
5
string FirstAndLast[string str]
2
// C++ program to remove the first
38
7 // C++ program to remove the first
40 // and last character of each word in a string.
74
{
// C++ program to remove the first
5_______5_______45string FirstAndLast[string str]
8// C++ program to remove the first
4
// C++ program to remove the first
5_______25_______82
// C++ program to remove the first
5_______25_______84
namespace
5
namespace
5
// and last character of each word in a string.
88
PHP
// and last character of each word in a string.
89
// and last character of each word in a string.
90
// and last character of each word in a string.
// and last character of each word in a string.
92 // and last character of each word in a string.
93// and last character of each word in a string.
94#include
6
{
// C++ program to remove the first
0
// and last character of each word in a string.
94 #include
01_______5_______3// C++ program to remove the first
4
#include
06 #include
07
#include
09 #include
07
// and last character of each word in a string.
4
// and last character of each word in a string.
6_______25_______7#include
17_______26_______18#include
17#include
20#include
21// and last character of each word in a string.
7// and last character of each word in a string.
94// C++ program to remove the first
06#include
17#include
26
{
// C++ program to remove the first
5_______26_______3// and last character of each word in a string.
7// and last character of each word in a string.
94#include
33#include
17#include
35#include
5#include
6
// C++ program to remove the first
5_______52_______
#include
9using
0
#include
9using
2
#include
9#include
06 #include
01#include
47// and last character of each word in a string.
7#include
09#include
50#include
21// and last character of each word in a string.
7#include
09#include
54