- substr: documentation ( source)
- strpos: documentation ( source)
- explode: documentation ( source)
- trim: documentation ( source)
<?php
function file_uri_scheme($uri) {
$position = strpos($uri, '://');
return $position ? substr($uri, 0, $position) : FALSE;
}
function file_uri_target($uri) {
$data = explode('://', $uri, 2);
// Remove erroneous leading or trailing, forward-slashes and backslashes.
return count($data) == 2 ? trim($data[1], '\/') : FALSE;
}
function file_stream_wrapper_uri_normalize($uri) {
$scheme = file_uri_scheme($uri);
if ($scheme) {
$target = file_uri_target($uri);
if ($target !== FALSE) {
$uri = $scheme . '://' . $target;
}
}
return $uri;
}
$uri = 'private://test/example.exe';
echo file_stream_wrapper_uri_normalize($uri);