本文整理汇总了PHP中Str::escapeRegex方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::escapeRegex方法的具体用法?PHP Str::escapeRegex怎么用?PHP Str::escapeRegex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Str
的用法示例。
在下文中一共展示了Str::escapeRegex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testEscapeRegex
function testEscapeRegex()
{
$this->assertEquals(1, preg_match("/\\\\b/", "\\b", $matches));
$this->assertEquals("\\.", Str::escapeRegex("."));
$this->assertEquals("\\\\b", Str::escapeRegex("\\b"));
$this->assertEquals("\\\\bold\\.", Str::escapeRegex("\\bold."));
}
示例2: getSimple
/**
* Get value for a given key but do no expression evaluation.
*
* @param string $key Key to use for message lookup.
* @param boolean $strict Whether to throw an error when key not found.
*
* @return string Message.
*
* @throws Exception if key not found and $strict == true.
*/
private function getSimple($key, $strict = FALSE)
{
// if null, empty, or starts with comment sequence of '#" or '//' - fail
// if in dev mode, check to see if exists multiple times and fail saying invalid property file
//use preg_match_all
// get regular expresion for matching key
$regex = self::PROP_VALUE_REGEX_PREPEND . Str::escapeRegex($key) . self::PROP_VALUE_REGEX_APPEND;
// find resource
preg_match($regex, $this->properties, $matches);
// if found, return it
if (isset($matches[1])) {
return $matches[1];
// not found, if not default, try to find in default resource
} else {
if (!$this->isDefault) {
preg_match($regex, $this->defaultProperties, $matches);
// if found, return it
if (isset($matches[1])) {
return $matches[1];
}
}
}
if ($strict) {
throw new Exception("The key \"" . $key . "\" was not found.");
} else {
return $key;
}
}