Làm cách nào để xóa ba ký tự ở cuối chuỗi trong PHP?
"ABCABCABC" sẽ trở thành "ABCABC"!
hỏi ngày 6 tháng 2 năm 2011 lúc 20:05Feb 6, 2011 at 20:05
1
Cứ làm đi:
echo substr[$string, 0, -3];
Bạn không cần sử dụng cuộc gọi strlen
, vì, như đã lưu ý trong tài liệu phụ:
Nếu độ dài được đưa ra và âm tính, thì nhiều ký tự sẽ bị bỏ qua từ cuối chuỗi
Đã trả lời ngày 6 tháng 2 năm 2011 lúc 20:10Feb 6, 2011 at 20:10
BENSIUBENSIUbensiu
Phù vàng 23.6K55 Huy hiệu vàng73 Huy hiệu bạc113 Huy hiệu đồng55 gold badges73 silver badges113 bronze badges
0
Đã trả lời ngày 6 tháng 2 năm 2011 lúc 20:09Feb 6, 2011 at 20:09
KOMARSERJIOKOMARSERJIOKomarSerjio
2.8231 Huy hiệu vàng15 Huy hiệu bạc12 Huy hiệu đồng1 gold badge15 silver badges12 bronze badges
0
Đã trả lời ngày 6 tháng 2 năm 2011 lúc 20:08Feb 6, 2011 at 20:08
Jan janJan
2.2571 Huy hiệu vàng17 Huy hiệu bạc16 Huy hiệu đồng1 gold badge17 silver badges16 bronze badges
1
[Php 4, Php 5, Php 7, Php 8]
RTRIM - Dải khoảng trắng [hoặc các ký tự khác] từ cuối chuỗi — Strip whitespace [or other characters] from the end of a string
Sự mô tả
rtrim [chuỗi $string
, chuỗi $characters
= "\ n \ r \ t \ v \ x00"]: Chuỗi[string $string
, string $characters
= " \n\r\t\v\x00"]: string
Không có tham số thứ hai, rtrim [] sẽ tước các ký tự sau:rtrim[] will strip these characters:
- "" [ASCII
32
[0x20
]], một không gian thông thường. - "\ t" [ASCII
9
[
0]], một tab. - "\ n" [ASCII
1 [
2]], một dòng mới [nguồn cấp dữ liệu]. - "\ r" [ASCII
3 [
4]], trả lại vận chuyển. - "\ 0" [ASCII
5 [
6]], ________ 17-byte. - "\ V" [ASCII
8 [
9]], một tab dọc.
Thông số
0Chuỗi đầu vào.
1Bạn cũng có thể chỉ định các ký tự bạn muốn tước, bằng tham số
1. Chỉ cần liệt kê tất cả các ký tự mà bạn muốn bị tước. Với
3, bạn có thể chỉ định một loạt các ký tự.Trả về giá trị
Trả về chuỗi sửa đổi.
Ví dụ
Ví dụ #1 Ví dụ sử dụng của RTRIM []rtrim[]
4
5
6Ví dụ trên sẽ xuất ra:
string[32] " These are a few words :] ... " string[16] " Example string " string[11] "Hello World" string[30] " These are a few words :] ..." string[26] " These are a few words :]" string[9] "Hello Wor" string[15] " Example string"
Xem thêm
- Trim [] - Dải khoảng trắng [hoặc các ký tự khác] từ đầu và cuối chuỗi
- LTRIM [] - Dải khoảng trắng [hoặc các ký tự khác] từ đầu chuỗi
Pinkgothic tại Gmail Dot Com ¶ ¶
12 năm trước
7
8
9Gbelanger tại exosecurance dot com ¶ ¶
16 năm trước
string[32] " These are a few words :] ... " string[16] " Example string " string[11] "Hello World" string[30] " These are a few words :] ..." string[26] " These are a few words :]" string[9] "Hello Wor" string[15] " Example string"0
string[32] " These are a few words :] ... " string[16] " Example string " string[11] "Hello World" string[30] " These are a few words :] ..." string[26] " These are a few words :]" string[9] "Hello Wor" string[15] " Example string"1
string[32] " These are a few words :] ... " string[16] " Example string " string[11] "Hello World" string[30] " These are a few words :] ..." string[26] " These are a few words :]" string[9] "Hello Wor" string[15] " Example string"2
string[32] " These are a few words :] ... " string[16] " Example string " string[11] "Hello World" string[30] " These are a few words :] ..." string[26] " These are a few words :]" string[9] "Hello Wor" string[15] " Example string"3
9Todd tại Magnifisites Dot Com ¶ ¶
19 năm trước
string[32] " These are a few words :] ... " string[16] " Example string " string[11] "Hello World" string[30] " These are a few words :] ..." string[26] " These are a few words :]" string[9] "Hello Wor" string[15] " Example string"5
Không được yêu cầu tại UniMaginedDesigns Dot Com ¶ ¶
17 năm trước
string[32] " These are a few words :] ... " string[16] " Example string " string[11] "Hello World" string[30] " These are a few words :] ..." string[26] " These are a few words :]" string[9] "Hello Wor" string[15] " Example string"6
string[32] " These are a few words :] ... " string[16] " Example string " string[11] "Hello World" string[30] " These are a few words :] ..." string[26] " These are a few words :]" string[9] "Hello Wor" string[15] " Example string"7
string[32] " These are a few words :] ... " string[16] " Example string " string[11] "Hello World" string[30] " These are a few words :] ..." string[26] " These are a few words :]" string[9] "Hello Wor" string[15] " Example string"8
string[32] " These are a few words :] ... " string[16] " Example string " string[11] "Hello World" string[30] " These are a few words :] ..." string[26] " These are a few words :]" string[9] "Hello Wor" string[15] " Example string"9
Pinkgothic tại Gmail Dot Com ¶ ¶
12 năm trước
strlen
0
strlen
1
strlen
2
strlen
3
strlen
4
9Gbelanger tại exosecurance dot com ¶ ¶
16 năm trước
strlen
6
strlen
7
strlen
8
strlen
9Todd tại Magnifisites Dot Com ¶ ¶
19 năm trước
$string
0
Không được yêu cầu tại UniMaginedDesigns Dot Com ¶ ¶
17 năm trước
$string
1
$string
2
99 năm trước ¶
16 năm trước
$string
4
$string
5
$string
6
$string
7
9Todd tại Magnifisites Dot Com ¶ ¶
19 năm trước
$string
9
$characters
0
$characters
1
$characters
2Không được yêu cầu tại UniMaginedDesigns Dot Com ¶ ¶
17 năm trước
9 năm trước
người điều hòa ¶ ¶
12 năm trước
$characters
4
$characters
5
9Gbelanger tại exosecurance dot com ¶ ¶
12 năm trước
$characters
4
$characters
5
9Gbelanger tại exosecurance dot com ¶ ¶
17 năm trước
32
0
32
1
32
2
32
3