Web lists-archives.com

[PHP] Re: How to escape a local path so fopen() doesn't consider it a URL?




Whoops again, the test should be for a scheme of 2 or more characters, not
1 or more (so it doesn't match C://foo):

function make_path_local(string $path): string {
  if (\preg_match('/^([a-zA-Z0-9+\\-.]{2,}:\\/\\/|data:|zlib:)/Ds', $path))
    return '.' . \DIRECTORY_SEPARATOR . $path;
  return $path;
}

​