Cách kiểm tra xem chuỗi có bảng chữ cái trong PHP không
Nội phân Chính showShow
- Sự mô tả
- Trả về giá trị
- Sự mô tả
- Trả về giá trị
- Làm thế nào kiểm tra chuỗi là tiếng Anh hoặc không trong PHP?
- Chữ số có trong PHP không?
- Làm thế nào để bạn kiểm tra xem một chuỗi có chứa một số trong PHP không?
- Làm cách nào để có được ký tự đầu tiên của chuỗi trong PHP?
CTYPE_ALPHA và CTYPE_DIGIT không giúp ích gì trong đó. là bất kỳ phương pháp của họ?
Đã hỏi ngày 17 tháng 3 năm 2014 lúc 15:17Mar 17, 2014 at 15:17
7
Bạn có thể sử dụng preg_match
cho điều này.
if[preg_match["/[a-z]/i", $string]]{
print "it has alphabet!";
}
Nếu bạn muốn kiểm tra tất cả các ký tự là bảng chữ cái, thì hãy sử dụng neo xung quanh Regex. Ví dụ ^[a-z]+$
.
Đã trả lời ngày 17 tháng 3 năm 2014 lúc 15:18Mar 17, 2014 at 15:18
Sabuj Hassansabuj HassanSabuj Hassan
37.2K12 Huy hiệu vàng73 Huy hiệu bạc84 Huy hiệu đồng12 gold badges73 silver badges84 bronze badges
Đăng theo yêu cầu
/^[a-zA-Z]+$/
alpha, /^[0-9]+$/
num, /^[a-zA-Z0-9]+$/
alpha-num
hoặc
/^\pL+$/u
UNI ALPHA, /^\pN+$/u
UNI NUM,
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.0 UNI ALPHA-NUM
Đã trả lời ngày 17 tháng 3 năm 2014 lúc 17:20Mar 17, 2014 at 17:20
[Php 4> = 4.0.4, Php 5, Php 7, Php 8]
CTYPE_ALPHA - Kiểm tra [các] ký tự chữ cái — Check for alphabetic character[s]
Sự mô tả
ctype_alpha [hỗn hợp The string KjgWZC consists of all letters.
The string arf12 does not consist of all letters.
1]: bool[mixed The string KjgWZC consists of all letters.
The string arf12 does not consist of all letters.
1]: bool
Thông số
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.2
Chuỗi được kiểm tra.
Ghi chú::
Nếu bao gồm một int giữa -128 và 255, nó được hiểu là giá trị ASCII của một ký tự duy nhất [giá trị âm có 256 được thêm vào để cho phép các ký tự trong phạm vi ASCII mở rộng]. Bất kỳ số nguyên nào khác được hiểu là một chuỗi chứa các chữ số thập phân của số nguyên.int between -128 and 255 inclusive is provided, it is interpreted as the ASCII value of a single character [negative values have 256 added in order to allow characters in the Extended ASCII range]. Any other integer is interpreted as a string containing the decimal digits of the integer.
Cảnh báo
Kể từ Php 8.1.0, việc chuyển một đối số không chuỗi được không phản đối. Trong tương lai, đối số sẽ được hiểu là một chuỗi thay vì một codepoint ASCII. Tùy thuộc vào hành vi dự định, đối số nên được chuyển vào chuỗi hoặc một cuộc gọi rõ ràng đến chr [] nên được thực hiện.string or an explicit call to chr[] should be made.
Trả về giá trị
Trả về
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.3 Nếu mọi ký tự trong
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.2 là một lá thư từ địa phương hiện tại,
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.5 khác. Khi được gọi với một chuỗi trống, kết quả sẽ luôn là
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.5.
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.3 if every character in
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.2 is a letter from the current locale,
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.5 otherwise. When called with an empty string the result will always be
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.5.
Ví dụ
Ví dụ #1 ví dụ CTYPE_ALPHA [] [sử dụng locale mặc định]ctype_alpha[] example [using the default locale]
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.7
Ví dụ trên sẽ xuất ra:
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.
Xem thêm
- CTYPE_UPPER [] - Kiểm tra [các] ký tự chữ hoa
- ctype_lower [] - Kiểm tra [các] ký tự chữ thường
- setlocale [] - Đặt thông tin địa phương
Tyrunur ¶ ¶
13 năm trước
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.8
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.9
The string AbCd1zyZ9 consists of all letters or digits. The string foo!#$bar does not consist of all letters or digits.0
The string AbCd1zyZ9 consists of all letters or digits. The string foo!#$bar does not consist of all letters or digits.1
[Php 4> = 4.0.4, Php 5, Php 7, Php 8]
CTYPE_ALPHA - Kiểm tra [các] ký tự chữ cái — Check for alphanumeric character[s]
Sự mô tả
ctype_alpha [hỗn hợp The string KjgWZC consists of all letters.
The string arf12 does not consist of all letters.
1]: bool[mixed The string KjgWZC consists of all letters.
The string arf12 does not consist of all letters.
1]: bool
Thông số
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.2
Chuỗi được kiểm tra.
Ghi chú::
Nếu bao gồm một int giữa -128 và 255, nó được hiểu là giá trị ASCII của một ký tự duy nhất [giá trị âm có 256 được thêm vào để cho phép các ký tự trong phạm vi ASCII mở rộng]. Bất kỳ số nguyên nào khác được hiểu là một chuỗi chứa các chữ số thập phân của số nguyên.int between -128 and 255 inclusive is provided, it is interpreted as the ASCII value of a single character [negative values have 256 added in order to allow characters in the Extended ASCII range]. Any other integer is interpreted as a string containing the decimal digits of the integer.
Cảnh báo
Kể từ Php 8.1.0, việc chuyển một đối số không chuỗi được không phản đối. Trong tương lai, đối số sẽ được hiểu là một chuỗi thay vì một codepoint ASCII. Tùy thuộc vào hành vi dự định, đối số nên được chuyển vào chuỗi hoặc một cuộc gọi rõ ràng đến chr [] nên được thực hiện.string or an explicit call to chr[] should be made.
Trả về giá trị
Trả về
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.3 Nếu mọi ký tự trong
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.2 là một lá thư từ địa phương hiện tại,
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.5 khác. Khi được gọi với một chuỗi trống, kết quả sẽ luôn là
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.5.
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.3 if every character in
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.2 is either a letter or a digit,
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.5 otherwise. When called with an empty string the result will always be
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.5.
Ví dụ
Ví dụ #1 ví dụ CTYPE_ALPHA [] [sử dụng locale mặc định]ctype_alnum[] example [using the default locale]
The string AbCd1zyZ9 consists of all letters or digits. The string foo!#$bar does not consist of all letters or digits.8
Ví dụ trên sẽ xuất ra:
The string AbCd1zyZ9 consists of all letters or digits. The string foo!#$bar does not consist of all letters or digits.
Xem thêm
- CTYPE_UPPER [] - Kiểm tra [các] ký tự chữ hoa
- ctype_lower [] - Kiểm tra [các] ký tự chữ thường
- setlocale [] - Đặt thông tin địa phương
Tyrunur ¶ ¶
13 năm trước
The string AbCd1zyZ9 consists of all letters or digits. The string foo!#$bar does not consist of all letters or digits.9
preg_match
0
preg_match
1
preg_match
2
preg_match
3
preg_match
4CTYPE_ALNUM - Kiểm tra [các] ký tự chữ và số ¶
ctype_alnum [hỗn hợp The string KjgWZC consists of all letters.
The string arf12 does not consist of all letters.
1]: bool
preg_match
5
preg_match
6
preg_match
7 Trả về The string KjgWZC consists of all letters.
The string arf12 does not consist of all letters.
3 Nếu mọi ký tự trong The string KjgWZC consists of all letters.
The string arf12 does not consist of all letters.
2 là một chữ cái hoặc một chữ số, The string KjgWZC consists of all letters.
The string arf12 does not consist of all letters.
5 khác. Khi được gọi với một chuỗi trống, kết quả sẽ luôn là The string KjgWZC consists of all letters.
The string arf12 does not consist of all letters.
5. ¶
Ví dụ #1 ví dụ CTYPE_ALNUM [] [sử dụng locale mặc định]
preg_match
8
CTYPE_ALPHA [] - Kiểm tra [các] ký tự chữ cái ¶
ctype_digit [] - Kiểm tra [các] ký tự số
preg_match
9
Làm thế nào kiểm tra chuỗi là tiếng Anh hoặc không trong PHP?
Thinice tại gmail dot comis_english['hello'];
Chữ số có trong PHP không?
Marcelocamargo tại Linuxmail Dot org ¶A ctype_alnum[] function in PHP used to check all characters of given string/text are alphanumeric or not. If all characters are alphanumeric then return TRUE, otherwise return FALSE.
Làm thế nào để bạn kiểm tra xem một chuỗi có chứa một số trong PHP không?
Làm cách nào để có được ký tự đầu tiên của chuỗi trong PHP?is_numeric[] function checks whether a variable is a number or a numeric string. This function returns true [1] if the variable is a number or a numeric string, otherwise it returns false/nothing.
Làm cách nào để có được ký tự đầu tiên của chuỗi trong PHP?
CTYPE_ALPHA và CTYPE_DIGIT không giúp ích gì trong đó. là bất kỳ phương pháp của họ?use the substr[] function by passing 0,1 as second and third arguments in PHP.