function drupal_match_path

Check if a path matches any pattern in a set of patterns.

Parameters

$path: The path to match.

$patterns: String containing a set of patterns separated by \n, \r or \r\n.

Return value

Boolean value: TRUE if the path matches a pattern, FALSE otherwise.

3 calls to drupal_match_path()
block_block_list_alter in drupal/core/modules/block/block.module
Implements hook_block_list_alter().
MatchPathTest::testDrupalMatchPath in drupal/core/modules/system/lib/Drupal/system/Tests/Path/MatchPathTest.php
Run through our test cases, making sure each one works as expected.
path_is_admin in drupal/core/includes/path.inc
Determine whether a path is in the administrative section of the site.

File

drupal/core/includes/path.inc, line 44
Functions to handle paths in Drupal.

Code

function drupal_match_path($path, $patterns) {
  $regexps =& drupal_static(__FUNCTION__);
  if (!isset($regexps[$patterns])) {

    // Convert path settings to a regular expression.
    // Therefore replace newlines with a logical or, /* with asterisks and the <front> with the frontpage.
    $to_replace = array(
      '/(\\r\\n?|\\n)/',
      // newlines
      '/\\\\\\*/',
      // asterisks
      '/(^|\\|)\\\\<front\\\\>($|\\|)/',
    );
    $replacements = array(
      '|',
      '.*',
      '\\1' . preg_quote(config('system.site')
        ->get('page.front'), '/') . '\\2',
    );
    $patterns_quoted = preg_quote($patterns, '/');
    $regexps[$patterns] = '/^(' . preg_replace($to_replace, $replacements, $patterns_quoted) . ')$/';
  }
  return (bool) preg_match($regexps[$patterns], $path);
}