You are here

static function RealisticDummyContentEnvironment::Replace in Realistic Dummy Content 7

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

RealisticDummyContentException

2 calls to RealisticDummyContentEnvironment::Replace()
RealisticDummyContentEnvironment::AttributeName in api/includes/RealisticDummyContentEnvironment.inc
Returns the attribute of a filename if one exists
RealisticDummyContentEnvironment::FilenameRadical in api/includes/RealisticDummyContentEnvironment.inc
Returns the name radical of a filename.

File

api/includes/RealisticDummyContentEnvironment.inc, line 392
Define RealisticDummyContentLiveEnvironment autoload class.

Class

RealisticDummyContentEnvironment
The abstract base environment.

Code

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