sapi_windows_vt100_support

(PHP 7 >= 7.2.0, PHP 8)

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

Description

sapi_windows_vt100_support(resource $stream, ?bool $enable = null): bool

If enable is null, the function returns true if the stream stream has VT100 control codes enabled, false otherwise.

If enable is a bool, 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.

Parameters

stream

The stream on which the function will operate.

enable

If bool, the VT100 feature will be enabled (if true) or disabled (if false).

Return Values

If enable is null: returns true if the VT100 feature is enabled, false otherwise.

If enable is a bool: Returns true on success or false on failure.

Changelog

Version Description
8.0.0 enable is now nullable.

Examples

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));"

The above example will output something similar to:

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

The above example will output something similar to:


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

The above example will output something similar to:

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');
?>

The above example will output:

Just forgot a letter.

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

PHP cURL Tutorial: Using cURL to Make HTTP Requests

cURL is a powerful PHP extension that allows you to communicate with different servers using various protocols, including HTTP, HTTPS, FTP, and more. ...

TheMax

Autor : TheMax
Category: PHP-Tutorials

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial