PHP stream_wrapper_unregister() Function
The PHP stream_wrapper_unregister() function is used to unregister a URL wrapper. It disables an already defined stream wrapper. Once the wrapper has been disabled it can be overridden with a user-defined wrapper using stream_wrapper_register() function or re-enabled later on using stream_wrapper_restore() function.
Syntax
stream_wrapper_unregister(protocol)
Parameters
protocol |
Required. Specify the wrapper name which need to be unregistered. |
Return Value
Returns true on success or false on failure.
Example:
The example below shows the usage of stream_wrapper_unregister() function.
<?php class VariableStream { //codes to implement methods like //stream_open, stream_write etc. } //checking the existence of 'var' stream //wrapper, if exists unregister it $existed = in_array("var", stream_get_wrappers()); if ($existed) { stream_wrapper_unregister("var"); } //register 'var' stream wrapper stream_wrapper_register("var", "VariableStream"); //opening the file $fp = fopen("var://test.txt", "w+"); //writing some content to it fwrite($fp, "line1 content\n"); fwrite($fp, "line2 content\n"); fwrite($fp, "line3 content\n"); //getting the starting position of the file rewind($fp); //reading the content of the file while (!feof($fp)) { echo fgets($fp); } //closing the file fclose($fp); //restore the 'var' stream wrapper //if previously existed if ($existed) { stream_wrapper_restore("var"); } ?>
The output of the above code will be:
line1 content line2 content line3 content
❮ PHP Streams Reference