Web lists-archives.com

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




Whoops, the regex should include 0-9 in the character range (the test in
the C code is isalnum() not isalpha()):

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

​