You are here

public static function RealisticDummyContentEnvironment::replace in Realistic Dummy Content 7.2

Same name and namespace in other branches
  1. 8.2 api/src/includes/RealisticDummyContentEnvironment.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentEnvironment::replace()
  2. 3.x api/src/includes/RealisticDummyContentEnvironment.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentEnvironment::replace()

Returns part of a filename.

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

Parameters

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

string $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

string 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/src/includes/RealisticDummyContentEnvironment.php
Returns the attribute of a filename if one exists.
RealisticDummyContentEnvironment::filenameRadical in api/src/includes/RealisticDummyContentEnvironment.php
Returns the name radical of a filename.

File

api/src/includes/RealisticDummyContentEnvironment.php, line 424

Class

RealisticDummyContentEnvironment
The abstract base environment.

Namespace

Drupal\realistic_dummy_content_api\includes

Code

public 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);
}