Điều này là để làm rõ thêm câu trả lời của JD Isaaks ...
Vấn đề bạn gặp phải thường xuyên là bạn đang sử dụng PHP để xuất HTML từ nhiều nguồn PHP khác nhau và các nguồn đó thường, vì bất kỳ lý do gì, xuất hiện thông qua các cách khác nhau.
Đôi khi bạn có nội dung HTML theo nghĩa đen mà bạn muốn trực tiếp xuất vào trình duyệt; Lần khác, đầu ra đang được tạo động [phía máy chủ].
Nội dung động luôn luôn [?] Sẽ là một chuỗi. Bây giờ bạn phải kết hợp HTML động được chuỗi này với bất kỳ HTML trực tiếp, trực tiếp đến hiện tại ... thành một cấu trúc nút HTML có ý nghĩa.
Điều này thường buộc nhà phát triển phải gói tất cả nội dung trực tiếp vào một chuỗi [như JD Isaak đang thảo luận] để nó có thể được phân phối/chèn đúng cách kết hợp với HTML động ... mặc dù bạn không thực sự muốn nó được bọc.
Nhưng bằng cách sử dụng các phương thức OB _ ##, bạn có thể tránh được mớ hỗn độn trong chuỗi đó. Thay vào đó, nội dung theo nghĩa đen là đầu ra cho bộ đệm. Sau đó, trong một bước dễ dàng, toàn bộ nội dung của bộ đệm [tất cả HTML theo nghĩa đen của bạn], được nối với chuỗi HTML động của bạn.
.
02 - component contents
Tracey tại Archive Dot org ¶
dan tại roteloftet dot com ¶ — Turn on output buffering
14 năm trước
Đồi Francois ¶[callable $callback
= null
, int $chunk_size
=
0, int $flags
= PHP_OUTPUT_HANDLER_STDFLAGS
]: bool
Lucky760 tại Yahoo Dot Com ¶ob_get_contents[]. To output what is stored in the internal buffer, use ob_end_flush[]. Alternatively, ob_end_clean[] will silently discard the buffer contents.
Filip Dalge ¶
null
8
Clancy Hood tại Gmail Dot Com ¶ob_start[] while another ob_start[] is active. Just make sure that you call ob_end_flush[] the appropriate number of times. If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order.
Nếu bộ đệm đầu ra vẫn hoạt động khi tập lệnh kết thúc, PHP sẽ tự động xuất nội dung.
Thông số
callback
Một hàm callback
tùy chọn có thể được chỉ định. Hàm này lấy một chuỗi làm tham số và sẽ trả về một chuỗi. Hàm sẽ được gọi khi bộ đệm đầu ra được xóa [đã gửi] hoặc làm sạch [bằng ob_flush [], ob_clean [] hoặc chức năng tương tự] hoặc khi bộ đệm đầu ra được xóa vào trình duyệt ở cuối yêu cầu. Khi callback
được gọi, nó sẽ nhận được nội dung của bộ đệm đầu ra làm tham số của nó và dự kiến sẽ trả về một bộ đệm đầu ra mới, kết quả sẽ được gửi đến trình duyệt. Nếu callback
không phải là hàm có thể gọi được, hàm này sẽ trả về
02 - component contents
3. Đây là chữ ký gọi lại:ob_flush[],
ob_clean[] or similar function] or when the output buffer is flushed to the browser at the end of the request. When callback
is called, it will receive the contents of the output buffer as its parameter and is expected to return a new output buffer as a result, which will be sent to the browser. If the callback
is not a callable function, this function will return
02 - component contents
3. This is the
callback signature: Handler [Chuỗi
4, int
5 =?]: Chuỗi[string
4, int
5 = ?]: string
02 - component contents
6 Nội dung của bộ đệm đầu ra.
02 - component contents
7 Bitmask của hằng số
02 - component contents
8. Contents of the output buffer.
02 - component contents
7 Bitmask of
02 - component contents
8 constants. Nếu callback
trả về
02 - component contents
3 Đầu vào gốc được gửi đến trình duyệt.
02 - component contents
3 original
input is sent to the browser. Tham số callback
có thể được bỏ qua bằng cách truyền giá trị null
.null
value.
ob_end_clean [], ob_end_flush [], ob_clean [], ob_flush [] và ob_start [] có thể không được gọi từ hàm gọi lại. Nếu bạn gọi họ từ chức năng gọi lại, hành vi không được xác định. Nếu bạn muốn xóa nội dung của bộ đệm, hãy trả về "" [chuỗi null] khỏi hàm gọi lại. Bạn thậm chí không thể gọi các chức năng bằng cách sử dụng các chức năng bộ đệm đầu ra như It's like comparing oranges to oranges. It's like comparing oranges to oranges.
3 hoặc
4 từ chức năng gọi lại., ob_end_flush[], ob_clean[],
ob_flush[] and ob_start[] may not be called from a callback function. If you call them from callback function, the behavior is undefined. If you would like to delete the contents of a buffer, return "" [a null string] from callback function. You can't even call functions using the output buffering functions like
3 orIt's like comparing oranges to oranges.
4 from a callback function.It's like comparing oranges to oranges.
Ghi chú::
Hàm ob_gzHandler [] tồn tại để tạo điều kiện gửi dữ liệu được mã hóa GZ đến các trình duyệt web hỗ trợ các trang web nén. ob_gzHandler [] xác định loại nội dung mã hóa trình duyệt sẽ chấp nhận và sẽ trả về đầu ra của nó cho phù hợp. function exists to facilitate sending gz-encoded data to web browsers that support compressed web pages. ob_gzhandler[] determines what type of content encoding the browser will accept and will return its output accordingly.
5It's like comparing oranges to oranges.
Nếu tham số tùy chọn
5 được truyền, bộ đệm sẽ được xóa sau khi bất kỳ cuộc gọi đầu ra nào khiến chiều dài của bộ đệm bằng hoặc vượt quáIt's like comparing oranges to oranges.
5. Giá trị mặc địnhIt's like comparing oranges to oranges.
8 có nghĩa là hàm đầu ra sẽ chỉ được gọi khi đóng bộ đệm đầu ra.It's like comparing oranges to oranges.
9It's like comparing oranges to oranges.
Tham số
9 là một bitmask kiểm soát các hoạt động có thể được thực hiện trên bộ đệm đầu ra. Mặc định là cho phép các bộ đệm đầu ra được làm sạch, xả và loại bỏ, có thể được đặt rõ ràng thông quaIt's like comparing oranges to oranges.
$callback
1 | $callback
2 | $callback
3, hoặc PHP_OUTPUT_HANDLER_STDFLAGS
như tốc ký.$callback
1 | $callback
2 | $callback
3, or PHP_OUTPUT_HANDLER_STDFLAGS
as shorthand. Mỗi cờ kiểm soát truy cập vào một tập hợp các chức năng, như được mô tả dưới đây:
$callback 1
| ob_clean [], ob_end_clean [] và ob_get_clean []., ob_end_clean[], and ob_get_clean[]. |
$callback 2
| ob_end_flush [], ob_flush [] và ob_get_flush []., ob_flush[], and ob_get_flush[]. |
$callback 3
| ob_end_clean [], ob_end_flush [] và ob_get_flush []., ob_end_flush[], and ob_get_flush[]. |
Trả về giá trị
Trả về $callback
8 khi thành công hoặc
02 - component contents
3 về thất bại.$callback
8 on success or
02 - component contents
3 on failure. Ví dụ
Ví dụ #1 Chức năng gọi lại do người dùng xác định
null
0
null
1
null
2Ví dụ trên sẽ xuất ra:
It's like comparing oranges to oranges.
Ví dụ #2 Tạo bộ đệm đầu ra không thể xác định được
null
3
null
4
null
5Xem thêm
- ob_get_contents [] - Trả về nội dung của bộ đệm đầu ra
- OB_END_CLEAN [] - Sạch [xóa] Bộ đệm đầu ra và tắt bộ đệm đầu ra
- ob_end_flush [] - Flush [Gửi] Bộ đệm đầu ra và tắt bộ đệm đầu ra
- ob_implicit_flush [] - Bật/tắt hết lần bật/tắt
- ob_gzHandler [] - hàm gọi lại ob_start thành bộ đệm đầu ra gzip
- ob_iconv_handler [] - Chuyển đổi mã hóa ký tự làm bộ đệm bộ đệm đầu ra
- mb_output_handler [] - chức năng gọi lại chuyển đổi mã hóa ký tự trong bộ đệm đầu ra
- ob_tidyHandler [] - chức năng gọi lại ob_start để sửa chữa bộ đệm
Ray Paseur [Paseur ... tưởng tượngB.com] ¶ ¶
17 năm trước
null
6
null
7
null
8ed.oohay [a] Suamhcs_rodnan ¶ ¶
19 năm trước
null
9
$chunk_size
0
$chunk_size
1
$chunk_size
2net_navard tại yahoo dot com ¶
16 năm trước
$chunk_size
3
$chunk_size
4
$chunk_size
5
$chunk_size
6
$chunk_size
7
$chunk_size
8
$chunk_size
9
null
8mjr ¶ ¶
18 năm trước
$flags
1
McHojrin tại gmail dot com ¶
10 năm trước
$flags
2
$flags
3
$flags
4
$flags
5
null
8Asher Haig [Ahaig tại RidiculousPower Dot Com] ¶ ¶
15 năm trước
$flags
7
$flags
8
$flags
9
null
8jhlavon ¶ ¶
9 năm trước
PHP_OUTPUT_HANDLER_STDFLAGS
1
PHP_OUTPUT_HANDLER_STDFLAGS
2
PHP_OUTPUT_HANDLER_STDFLAGS
3
null
8Mbutscher tại GMX Dot de ¶ ¶
6 năm trước
PHP_OUTPUT_HANDLER_STDFLAGS
5
PHP_OUTPUT_HANDLER_STDFLAGS
6
PHP_OUTPUT_HANDLER_STDFLAGS
7
PHP_OUTPUT_HANDLER_STDFLAGS
8Chris ¶ ¶
12 năm trước
PHP_OUTPUT_HANDLER_STDFLAGS
9
chdir[dirname[$_SERVER['SCRIPT_FILENAME']]]
0
chdir[dirname[$_SERVER['SCRIPT_FILENAME']]]
1
chdir[dirname[$_SERVER['SCRIPT_FILENAME']]]
2
null
8Ernest tại Vogelsinger Dot tại ¶ ¶
16 năm trước
chdir[dirname[$_SERVER['SCRIPT_FILENAME']]]
4
chdir[dirname[$_SERVER['SCRIPT_FILENAME']]]
5
chdir[dirname[$_SERVER['SCRIPT_FILENAME']]]
6
chdir[dirname[$_SERVER['SCRIPT_FILENAME']]]
7
chdir[dirname[$_SERVER['SCRIPT_FILENAME']]]
8
chdir[dirname[$_SERVER['SCRIPT_FILENAME']]]
9
null
8mjr ¶ ¶
18 năm trước
callback
1
callback
2
callback
3
null
8McHojrin tại gmail dot com ¶
15 năm trước
callback
5
callback
6
callback
7
null
8jhlavon ¶ ¶
9 năm trước
callback
9
02 - component contents
00
02 - component contents
01
02 - component contents
02null
8Mbutscher tại GMX Dot de ¶ ¶
15 năm trước
02 - component contents
04
02 - component contents
05null
8jhlavon ¶ ¶
16 năm trước
02 - component contents
07
02 - component contents
08
02 - component contents
09
02 - component contents
10
02 - component contents
11
02 - component contents
12
02 - component contents
13Filip Dalge ¶ ¶
10 năm trước
02 - component contents
14
02 - component contents
15
02 - component contents
16
02 - component contents
17null
8Clancy Hood tại Gmail Dot Com ¶ ¶
13 năm trước
02 - component contents
19
02 - component contents
20
02 - component contents
21Charlie Farrow ¶ ¶
15 năm trước
02 - component contents
22
02 - component contents
23
02 - component contents
24null
8Quản trị viên tại Bobfrank Dot org ¶ ¶
17 năm trước
02 - component contents
26
02 - component contents
27
02 - component contents
28
02 - component contents
29null
8bty-adminf2 tại trbly dot net ¶ ¶
7 năm trước
02 - component contents
31
02 - component contents
32
02 - component contents
33
02 - component contents
34
02 - component contents
35
02 - component contents
36null
8Aaron tại OffTone.com ¶ ¶
18 năm trước
02 - component contents
38
02 - component contents
39
02 - component contents
40null
8tôi tại haravikk dot com ¶ ¶
10 năm trước
02 - component contents
42
02 - component contents
43
02 - component contents
44null
8 null
8 ¶
Clancy Hood tại Gmail Dot Com ¶
02 - component contents
46
02 - component contents
47
02 - component contents
48
02 - component contents
49
02 - component contents
50null
813 năm trước ¶
Charlie Farrow ¶
02 - component contents
52
02 - component contents
53null
813 năm trước ¶
17 năm trước
02 - component contents
55
02 - component contents
56
02 - component contents
57
02 - component contents
58null
8bty-adminf2 tại trbly dot net ¶ ¶
17 năm trước
02 - component contents
60
02 - component contents
61
02 - component contents
62
02 - component contents
63null
8bty-adminf2 tại trbly dot net ¶ ¶
17 năm trước
02 - component contents
65
02 - component contents
66
02 - component contents
67
02 - component contents
68bty-adminf2 tại trbly dot net ¶ ¶
13 năm trước
02 - component contents
69
02 - component contents
70
02 - component contents
71
02 - component contents
72Charlie Farrow ¶ ¶
13 năm trước
02 - component contents
73
02 - component contents
74
02 - component contents
75
02 - component contents
76
02 - component contents
76
02 - component contents
78
02 - component contents
79null
8Charlie Farrow ¶ ¶
13 năm trước
02 - component contents
81
02 - component contents
82null
8Charlie Farrow ¶ ¶
15 năm trước
02 - component contents
84
02 - component contents
85
02 - component contents
86
02 - component contents
87Quản trị viên tại Bobfrank Dot org ¶ ¶
15 năm trước
02 - component contents
88
02 - component contents
89
02 - component contents
90null
8Quản trị viên tại Bobfrank Dot org ¶ ¶
16 năm trước
02 - component contents
92
02 - component contents
93
02 - component contents
94
02 - component contents
95null
817 năm trước ¶
16 năm trước
02 - component contents
97bty-adminf2 tại trbly dot net ¶ ¶
17 năm trước
02 - component contents
98
02 - component contents
99null
8bty-adminf2 tại trbly dot net ¶ ¶
17 năm trước
01It's like comparing oranges to oranges.
02It's like comparing oranges to oranges.
03It's like comparing oranges to oranges.
04It's like comparing oranges to oranges.
null
813 năm trước ¶
Charlie Farrow ¶
06It's like comparing oranges to oranges.
07It's like comparing oranges to oranges.
08It's like comparing oranges to oranges.
09It's like comparing oranges to oranges.
10It's like comparing oranges to oranges.
11It's like comparing oranges to oranges.
12It's like comparing oranges to oranges.
null
815 năm trước ¶
15 năm trước
14It's like comparing oranges to oranges.
15It's like comparing oranges to oranges.
16It's like comparing oranges to oranges.
17It's like comparing oranges to oranges.
18It's like comparing oranges to oranges.
null
8