W3cubDocs

/Drupal 8

public function FileSystem::uriScheme

public FileSystem::uriScheme($uri)

Returns the scheme of a URI (e.g. a stream).

Parameters

string $uri: A stream, referenced as "scheme://target" or "data:target".

Return value

string|bool A string containing the name of the scheme, or FALSE if none. For example, the URI "public://example.txt" would return "public".

Overrides FileSystemInterface::uriScheme

See also

file_uri_target()

File

core/lib/Drupal/Core/File/FileSystem.php, line 283

Class

FileSystem
Provides helpers to operate on files and stream wrappers.

Namespace

Drupal\Core\File

Code

public function uriScheme($uri) {
  if (preg_match('/^([\w\-]+):\/\/|^(data):/', $uri, $matches)) {
    // The scheme will always be the last element in the matches array.
    return array_pop($matches);
  }

  return FALSE;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!File!FileSystem.php/function/FileSystem::uriScheme/8.1.x