PHP 출력 제어 기능
PHP 출력 제어 기능
PHP는 어떤 콘텐츠가 언제 브라우저로 전송되는지를 제어하는 일련의 기능을 제공합니다. 이것을 출력 제어 라고 합니다 .
출력은 다음 소스 중 하나에서 올 수 있습니다.
echo
,print
,printf
,print_r
... 및 기타 유사한 기능 및 명령문- PHP의 주의 사항, 경고 및 오류
<?php ?>
태그 외부의 모든 콘텐츠
PHP와 PHP가 실행되는 백엔드는 출력을 사용자에게 보내기 전에 버퍼에 보관할 수 있습니다.
참고: 출력 제어 기능은 원하는 수의 출력 버퍼를 생성할 수 있습니다. 출력 버퍼는 프로그램에서 제공한 출력을 포착합니다. 각각의 새로운 출력 버퍼는 출력 버퍼 스택의 맨 위에 배치되며, 제공하는 모든 출력은 그 아래의 버퍼에 의해 포착됩니다. 출력 제어 함수는 최상위 버퍼만 처리하므로 그 아래의 버퍼를 제어하려면 최상위 버퍼를 제거해야 합니다.
설치
PHP 출력 제어 기능은 PHP 코어의 일부입니다. 이러한 기능을 사용하기 위해 설치가 필요하지 않습니다.
런타임 구성
출력 제어 기능의 동작은 php.ini 설정의 영향을 받습니다.
Name | Default | Description | Version |
---|---|---|---|
output_buffering | "0" | Enables output buffering for all PHP files by default | 4 |
output_handler | NULL | Set the name of the default function which handles the output of all output buffers | 4 |
implicit_flush | "0" | Enables implicit flush, which causes output to be sent directly to the browser on each output statement | 4 |
url_rewriter.tags | "a=href,area=href, frame=src,form=,fieldset=" | Indicates which HTML tags and attributes can be modified by the URL rewriter (the output_add_rewrite_var() function.) | 4.3 |
url_rewriter.hosts | The current value of $_SERVER['HTTP_HOST'] | URL rewriting is only done on the server's own URLs by default. To allow for rewriting URLs of other websites, set the hostnames of the other websites here. | 7.1 |
PHP 출력 제어 기능
Method | Function |
---|---|
flush() | Attempts to send content from the system's output buffer to the browser |
ob_clean() | Deletes all of the content from the topmost output buffer |
ob_end_clean() | Deletes the topmost output buffer and all of its contents |
ob_end_flush() | Deletes the topmost output buffer and outputs its contents |
ob_flush() | Outputs the contents of the topmost output buffer and clears the buffer |
ob_get_clean() | Returns all of the contents of the topmost output buffer and clears the buffer |
ob_get_contents() | Returns the contents of the topmost output buffer |
ob_get_flush() | Outputs and returns the contents of the topmost output buffer and then deletes the buffer |
ob_get_length() | Returns the number of bytes of data that are in the topmost output buffer |
ob_get_level() | Returns a number indicating how many output buffers are on the stack |
ob_get_status() | Returns information about the output buffers |
ob_gzhandler() | Used as a callback function for ob_start() to compress the contents of the buffer when sending it to the browser |
ob_implicit_flush() | Turns implicit flushing on or off |
ob_list_handlers() | Returns an array of callback function names that are being used by the topmost output buffer |
ob_start() | Creates a new output buffer and adds it to the top of the stack |
output_add_rewrite_var() | Used to append query string parameters to any URL in the output |
output_reset_rewrite_vars() | Removes all variables added by output_add_rewrite_var() |