You are here

static function Environment::Replace in Realistic Dummy Content 8

Returns part of a filename

Helper function which runs a preg replace function on a filename and returns the result

Parameters

$filename: A filename, for example a, a.b, a.b.c, a.b.c.d

$replace: A replacement pattern meant to be passed to preg_replace, where: \1 = everything before the next-to-last period \2 = everything between the next-to-last and last periods. \3 = everything after and including the last period

Return value

The replaced filename, or the same filename in case of an error or if the pattern is not found.

Throws

Exception

2 calls to Environment::Replace()
Environment::AttributeName in api/src/environments/Environment.php
Returns the attribute of a filename if one exists
Environment::FilenameRadical in api/src/environments/Environment.php
Returns the name radical of a filename.

File

api/src/environments/Environment.php, line 389
Define autoload class.

Class

Environment
The abstract base environment.

Namespace

Drupal\realistic_dummy_content_api\environments

Code

static function Replace($filename, $replace) {
  if (!is_string($filename)) {
    throw new Exception('Please pass ' . __FUNCTION__ . ' a string as a filename, not a ' . gettype($filename));
  }
  return preg_replace('/(^.*)\\.([^\\.]*)(\\.[^\\.]*$)/', $replace, $filename);
}