當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Str::escapeRegex方法代碼示例

本文整理匯總了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."));
 }
開發者ID:Rkandel23,項目名稱:ubar,代碼行數:7,代碼來源:StrTest.php

示例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;
     }
 }
開發者ID:Rkandel23,項目名稱:ubar,代碼行數:38,代碼來源:LocalizedProperties.php


注:本文中的Str::escapeRegex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。