sapi_windows_vt100_support

(PHP 7 >= 7.2.0)

sapi_windows_vt100_supportGet or set VT100 support for the specified stream associated to an output buffer of a Windows console.

说明

sapi_windows_vt100_support ( resource $stream [, bool $enable ] ) : bool

If enable is omitted, the function returns TRUE if the stream stream has VT100 control codes enabled, FALSE otherwise.

If enable is specified, the function will try to enable or disable the VT100 features of the stream stream. If the feature has been successfully enabled (or disabled), the function will return TRUE, or FALSE otherwise.

At startup, PHP tries to enable the VT100 feature of the STDOUT/STDERR streams. By the way, if those streams are redirected to a file, the VT100 features may not be enabled.

If VT100 support is enabled, it is possible to use control sequences as they are known from the VT100 terminal. They allow the modification of the terminal's output. On Windows these sequences are called Console Virtual Terminal Sequences.

Warning

This function uses the ENABLE_VIRTUAL_TERMINAL_PROCESSING flag implemented in the Windows 10 API, so the VT100 feature may not be available on older Windows versions.

参数

stream

The stream on which the function will operate.

enable

If specified, the VT100 feature will be enabled (if TRUE) or disabled (if FALSE).

返回值

If enable is not specified: returns TRUE if the VT100 feature is enabled, FALSE otherwise.

If enable is specified: 成功时返回 TRUE, 或者在失败时返回 FALSE

范例

Example #1 sapi_windows_vt100_support() default state

By default, STDOUT and STDERR have the VT100 feature enabled.

php -r "var_export(sapi_windows_vt100_support(STDOUT));echo ' ';var_export(sapi_windows_vt100_support(STDERR));"

以上例程的输出类似于:

true true

By the way, if a stream is redirected, the VT100 feature will not be enabled:

php -r "var_export(sapi_windows_vt100_support(STDOUT));echo ' ';var_export(sapi_windows_vt100_support(STDERR));" 2>NUL

以上例程的输出类似于:


true false

Example #2 sapi_windows_vt100_support() changing state

You won't be able to enable the VT100 feature of STDOUT or STDERR if the stream is redirected.

php -r "var_export(sapi_windows_vt100_support(STDOUT, true));echo ' ';var_export(sapi_windows_vt100_support(STDERR, true));" 2>NUL

以上例程的输出类似于:

true false

Example #3 Example usage of VT100 support enabled

<?php
$out 
fopen('php://stdout','w');
fwrite($out'Just forgot a lettr.');
// Moves the cursor two characters backwards
fwrite($out"\033[2D");
// Inserts one blank, shifting existing text to the right -> Just forgot a lett r.
fwrite($out"\033[1@");
fwrite($out'e');
?>

以上例程会输出:

Just forgot a letter.
相关文章
php eventbufferevent returns underlying output buffer associated with current buffer eventphp ibm db2 函数 returns a result set listing the columns and associated privileges for a tablephp ibm db2 函数 returns a result set listing the columns and associated metadata for a tablephp ibm db2 函数 returns a result set listing the tables and associated privileges in a databasephp ibm db2 函数 returns a result set listing the tables and associated metadata in a databasephp expect 函数 waits until the output from a process matches one of the patterns a specified time period has passed or an eof is seenphp frontbase 函数 change input/output character setphp ingres 函数 set environment features controlling output optionsphp maxdb 函数 set result pointer to a specified field offsetphp ncurses 函数 moves windows output positionphp output control 函数 在ob start中使用的用来压缩输出缓冲区中内容的回调函数。ob start callback function to gzip output bufferphp 杂项 函数 get or set vt100 support for the specified stream associated to an output buffer of a windows console.php 文件系统函数 stream set write buffer 的别名php snmp 函数 set the oid output formatphp snmp 函数 set the oid output formatphp 网络 函数 别名 stream set blockingphp 网络 函数 别名 stream set timeoutphp stream 函数 set the default stream contextphp stream 函数 set parameters for a stream/wrapper/contextphp stream 函数 runs the equivalent of the select system call on the given arrays of streams with a timeout specified by tv sec and tv usec
关注编程学问公众号