PHP | stream_get_wrappers() Function

The stream_get_wrappers() function is an inbuilt function in PHP which is used to get the list of registered streams available on the running system.

Syntax:

array stream_get_wrappers( void )

Parameters: This function does not accept any parameter.



Return Value: The function returns an array containing the name of all available streams.

Below programs illustrate the stream_get_wrappers() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// PHP program to illustrate
// stream_get_wrappers function
  
print_r(stream_get_wrappers());
?>

chevron_right


Output:

Array
(
    [0] => https
    [1] => ftps
    [2] => compress.zlib
    [3] => php
    [4] => file
    [5] => glob
    [6] => data
    [7] => http
    [8] => ftp
    [9] => phar
)

Program 2: Program to check the given streams are available or not.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// PHP program to illustrate
// stream_get_wrappers function
  
$wrapper = array (
    'https',
    'http',
    'file',
    'data',
    'GFG'
);
  
// Checking stream wrapper enabled or not
foreach ($wrapper as &$gfg) {
    if (in_array($gfg, stream_get_wrappers())) {
        echo $gfg . ': Enabled' . "\n";
    } else {
        echo $gfg . ": Not Enabled" . "\n";
    }
}
  
?>

chevron_right


Output:

https: Enabled
http: Enabled
file: Enabled
data: Enabled
GFG: Not Enabled

Reference: http://php.net/manual/en/function.stream-get-wrappers.php



My Personal Notes arrow_drop_up

Recommended Posts:



    Article Tags :

    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.