Chuỗi php thành char

$text   = "\t\tThese are a few words :] ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
var_dump[$text, $binary, $hello];

print "\n";

$trimmed = trim[$text];
var_dump[$trimmed];

$trimmed = trim[$text, " \t."];
var_dump[$trimmed];

$trimmed = trim[$hello, "Hdle"];
var_dump[$trimmed];

$trimmed = trim[$hello, 'HdWr'];
var_dump[$trimmed];

// trim the ASCII control characters at the beginning and end of $binary
// [from 0 to 31 inclusive]
$clean = trim[$binary, "\x00..\x1F"];
var_dump[$clean];

________số 8

Note: function return NULL if can't convert argument type.

$text   = "\t\tThese are a few words :] ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
var_dump[$text, $binary, $hello];
0

$text   = "\t\tThese are a few words :] ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
var_dump[$text, $binary, $hello];
1

$text   = "\t\tThese are a few words :] ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
var_dump[$text, $binary, $hello];
2

Nếu tham số $text   = "\t\tThese are a few words :] ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
var_dump[$text, $binary, $hello];
3 tùy chọn được chỉ định, thì mảng được trả về sẽ được chia thành các đoạn với mỗi đoạn có chiều dài $text   = "\t\tThese are a few words :] ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
var_dump[$text, $binary, $hello];
3, ngoại trừ đoạn cuối cùng có thể ngắn hơn nếu chuỗi không chia đều. $text   = "\t\tThese are a few words :] ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
var_dump[$text, $binary, $hello];
3 mặc định là $text   = "\t\tThese are a few words :] ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
var_dump[$text, $binary, $hello];
6, nghĩa là mỗi đoạn sẽ có kích thước một byte

Lỗi/Ngoại lệ

Nếu $text   = "\t\tThese are a few words :] ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
var_dump[$text, $binary, $hello];
3 nhỏ hơn $text   = "\t\tThese are a few words :] ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
var_dump[$text, $binary, $hello];
6, một ValueError sẽ được đưa ra

Nhật ký thay đổi

Phiên bảnMô tả8. 0. 0Nếu $text   = "\t\tThese are a few words :] ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
var_dump[$text, $binary, $hello];
3 nhỏ hơn $text   = "\t\tThese are a few words :] ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
var_dump[$text, $binary, $hello];
6, một ValueError sẽ được đưa ra ngay bây giờ;

ví dụ

Ví dụ #1 Ví dụ sử dụng str_split[]

print "\n";15

print "\n";16

print "\n";17

print "\n";18

Ví dụ trên sẽ xuất ra

Array
[
    [0] => H
    [1] => e
    [2] => l
    [3] => l
    [4] => o
    [5] =>
    [6] => F
    [7] => r
    [8] => i
    [9] => e
    [10] => n
    [11] => d
]

Array
[
    [0] => Hel
    [1] => lo
    [2] => Fri
    [3] => end
]

ghi chú

Ghi chú

str_split[] sẽ chia thành byte, thay vì ký tự khi xử lý chuỗi được mã hóa nhiều byte. Sử dụng mb_str_split[] để chia chuỗi thành các điểm mã

print "\n";7

print "\n";8

print "\n";9

$trimmed = trim[$text];
var_dump[$trimmed];
0

$trimmed = trim[$text];
var_dump[$trimmed];
1

$trimmed = trim[$text];
var_dump[$trimmed];
2

$trimmed = trim[$text];
var_dump[$trimmed];
3

$trimmed = trim[$text];
var_dump[$trimmed];
4

$trimmed = trim[$text];
var_dump[$trimmed];
5

$trimmed = trim[$text];
var_dump[$trimmed];
6

print "\n";80

Chủ Đề