当前位置: 首页>>代码示例>>PHP>>正文


PHP preg_last_error函数代码示例

本文整理汇总了PHP中preg_last_error函数的典型用法代码示例。如果您正苦于以下问题:PHP preg_last_error函数的具体用法?PHP preg_last_error怎么用?PHP preg_last_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了preg_last_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setRegexpMatch

 /**
  * Sets a regular expression tested against the current value of the object
  * or when the value is set. See verifyValue.
  * @param string $match
  */
 public function setRegexpMatch($match)
 {
     $test = '';
     if (!empty($this->value)) {
         $test = $this->value;
     }
     if (preg_match($match, $test) === false) {
         throw new \Exception(t('Regular expression error: %s', preg_error_msg(preg_last_error())));
     }
     $this->regexp_match = $match;
 }
开发者ID:HaldunA,项目名称:phpwebsite,代码行数:16,代码来源:String.php

示例2: matchOffset

 private function matchOffset($buffer, $offset, $pattern, $index)
 {
     $return = NULL;
     $found = preg_match($pattern, $buffer, $match, PREG_OFFSET_CAPTURE, $offset);
     if (false === $found) {
         $error = preg_last_error();
         throw new UnexpectedValueException(sprintf('Regular expression ("%s") failed (Error-Code: %d).', $pattern, $error));
     }
     $found && isset($match[$index][1]) && $match[$index][1] === $offset && ($return = $match[$index][0]);
     return $return;
 }
开发者ID:ktomk,项目名称:PhpCss,代码行数:11,代码来源:Status.php

示例3: smarty_outputfilter_shortcodes

function smarty_outputfilter_shortcodes($output, Smarty_Internal_Template $template)
{
    $shortcodes = \Xoops\Core\Text\Sanitizer::getInstance()->getShortCodes();
    $shortcodes->addShortcode('nosc42', function ($attributes, $content, $tagName) {
        return $content;
    });
    // break out the body content
    $bodyPattern = '/<body[^>]*>(.*?)<\\/body>/is';
    // breaks out form elements
    $scPattern = '/((<textarea[\\S\\s]*\\/textarea>)|(<input[\\S\\s]*>)|(<select[\\S\\s]*\\/select>)|(<script[\\S\\s]*\\/script>)|(<style[\\S\\s]*\\/style>))/U';
    $text = preg_replace_callback($bodyPattern, function ($matches) use($scPattern, $shortcodes) {
        $element = preg_replace_callback($scPattern, function ($innerMatches) {
            return '[nosc42]' . $innerMatches[0] . '[/nosc42]';
        }, $matches[1]);
        if ($element === null) {
            trigger_error('preg_last_error=' . preg_last_error(), E_USER_WARNING);
            return $matches[1];
        }
        return $element;
    }, $output);
    if ($text === null) {
        trigger_error('preg_last_error=' . preg_last_error(), E_USER_WARNING);
        return $output;
    }
    $text = $shortcodes->process($text);
    return $text;
}
开发者ID:ming-hai,项目名称:XoopsCore,代码行数:27,代码来源:outputfilter.shortcodes.php

示例4: _preg_error

 private function _preg_error()
 {
     switch (preg_last_error()) {
         case PREG_INTERNAL_ERROR:
             echo 'PREG_INTERNAL_ERROR';
             break;
         case PREG_BACKTRACK_LIMIT_ERROR:
             echo 'PREG_BACKTRACK_LIMIT_ERROR';
             break;
         case PREG_RECURSION_LIMIT_ERROR:
             echo 'PREG_RECURSION_LIMIT_ERROR';
             break;
         case PREG_BAD_UTF8_ERROR:
             echo 'PREG_BAD_UTF8_ERROR';
             break;
         case PREG_BAD_UTF8_OFFSET_ERROR:
             echo 'PREG_BAD_UTF8_OFFSET_ERROR';
             break;
         default:
             //die("Unknown preg error.");
             return;
     }
     echo "<hr><pre>";
     debug_print_backtrace();
     die;
 }
开发者ID:nextgensh,项目名称:friendica,代码行数:26,代码来源:template_processor.php

示例5: _checkError

 private static function _checkError()
 {
     $code = preg_last_error();
     if ($code != PREG_NO_ERROR) {
         self::_throwError($code);
     }
 }
开发者ID:bdusell,项目名称:jitsu-regex,代码行数:7,代码来源:RegexUtil.php

示例6: process

	/**
	 * @param  TexyBlockParser
	 * @param  string     text
	 * @param  array
	 * @param  TexyHtml
	 * @return vois
	 */
	public function process($parser, $content, $el)
	{
		$tx = $this->texy;

		if ($parser->isIndented()) {
			$parts = preg_split('#(\n(?! )|\n{2,})#', $content, -1, PREG_SPLIT_NO_EMPTY);
		} else {
			$parts = preg_split('#(\n{2,})#', $content, -1, PREG_SPLIT_NO_EMPTY);
		}

		foreach ($parts as $s)
		{
			$s = trim($s);
			if ($s === '') continue;

			// try to find modifier
			$mx = $mod = NULL;
			if (preg_match('#'.TEXY_MODIFIER_H.'(?=\n|\z)#sUm', $s, $mx, PREG_OFFSET_CAPTURE)) {
				list($mMod) = $mx[1];
				$s = trim(substr_replace($s, '', $mx[0][1], strlen($mx[0][0])));
				if ($s === '') continue;
				$mod = new TexyModifier;
				$mod->setProperties($mMod);

			} elseif (TEXY_CHECK_PCRE && preg_last_error()) {
				throw new TexyPcreException;
			}

			$res = $tx->invokeAroundHandlers('paragraph', $parser, array($s, $mod));
			if ($res) $el->insert(NULL, $res);
		}
	}
开发者ID:JanTvrdik,项目名称:StaticWeb,代码行数:39,代码来源:TexyParagraphModule.php

示例7: trim

 static function trim($value, $max_length, $is_html = false)
 {
     if (UTF8::len($value) > $max_length) {
         $value = UTF8::sub($value, 0, $max_length);
         // TODO: replace this with cleanstring of ctools
         $regex = '(.*)\\b.+';
         $matches = array();
         if (function_exists('mb_ereg')) {
             mb_regex_encoding('UTF-8');
             $found = mb_ereg($regex, $value, $matches);
         } else {
             $found = preg_match("/{$regex}/us", $value, $matches);
         }
         if ($found) {
             $value = $matches[1];
         }
         if ($is_html) {
             // Remove scraps of HTML entities from the end of a strings
             $regex = '/(?:<(?!.+>)|&(?!.+;)).*$/s';
             $value2 = preg_replace($regex . 'u', '', $value);
             if (preg_last_error() == 4) {
                 $value = preg_replace($regex, '', $value);
             } else {
                 $value = $value2;
             }
         }
         $value = rtrim($value);
         $value .= '...';
     }
     if ($is_html) {
         $value = self::_filter_htmlcorrector($value);
     }
     return $value;
 }
开发者ID:splitice,项目名称:radical-basic,代码行数:34,代码来源:Truncate.php

示例8: __construct

 /**
  * Construct the exception. Note: The message is NOT binary safe.
  *
  * @param string    $message  Description where regex error occurred.
  * @param string    $regex    Pattern which caused error.
  * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0
  */
 public function __construct($message, $regex, Exception $previous = null)
 {
     $lastError = preg_last_error();
     $lastErrorText = isset($this->pregErrors[$lastError]) ? $this->pregErrors[$lastError] : "preg error #{$lastError}";
     $message .= ". Pattern {$regex} cannot be used" . ($lastError === PREG_NO_ERROR ? '.' : ": {$lastErrorText}.");
     parent::__construct($message, 0, $previous);
 }
开发者ID:kiler129,项目名称:TorrentGhost,代码行数:14,代码来源:RegexException.php

示例9: tokenize

 function tokenize($source)
 {
     $result = new TokenStream();
     $pos = 0;
     $matches = array();
     preg_match_all($this->pattern, $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
     if (preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR) {
         throw new TemplateSyntaxError('Template too large, PCRE backtrack limit reached');
     }
     foreach ($matches as $match) {
         if (!isset($match["match"])) {
             throw new TemplateSyntaxError('Template error');
         }
         $tagpos = $match["match"][1];
         if ($tagpos > 0) {
             $text = substr($source, $pos, $tagpos - $pos);
             $result->feed('text', $text, $pos);
         }
         if (isset($match["block"]) && $match["block"][1] != -1) {
             $result->feed('block', trim($match["block"][0]), $tagpos);
         } elseif (isset($match["variable"]) && $match["variable"][1] != -1) {
             $result->feed('variable', trim($match["variable"][0]), $tagpos);
         } elseif (iset($match["comment"]) && $match["comment"][1] != -1) {
             $result->feed('comment', trim($match["comment"][0]), $tagpos);
         }
         $pos = $tagpos + strlen($match["match"][0]);
     }
     if ($pos < strlen($source)) {
         $result->feed('text', substr($source, $pos), $pos);
     }
     $result->close();
     return $result;
 }
开发者ID:hbasria,项目名称:h2o-php,代码行数:33,代码来源:parser.php

示例10: preg_error_message

 function preg_error_message($code = null)
 {
     if ($code === null) {
         $code = preg_last_error();
     }
     $code = (int) $code;
     switch ($code) {
         case PREG_NO_ERROR:
             $result = 'PCRE: No error, probably invalid regular expression.';
             break;
         case PREG_INTERNAL_ERROR:
             $result = 'PCRE: Internal error.';
             break;
         case PREG_BACKTRACK_LIMIT_ERROR:
             $result = 'PCRE: Backtrack limit has been exhausted.';
             break;
         case PREG_RECURSION_LIMIT_ERROR:
             $result = 'PCRE: Recursion limit has been exhausted.';
             break;
         case PREG_BAD_UTF8_ERROR:
             $result = 'PCRE: Malformed UTF-8 data.';
             break;
         default:
             if (is_php('5.3') && $code == PREG_BAD_UTF8_OFFSET_ERROR) {
                 $result = 'PCRE: Did not end at a valid UTF-8 codepoint.';
             } elseif (is_php('7') && $code == PREG_JIT_STACKLIMIT_ERROR) {
                 $result = 'PCRE: Failed because of limited JIT stack space.';
             } else {
                 $result = 'PCRE: Error ' . $code . '.';
             }
             break;
     }
     return $result;
 }
开发者ID:acamboy,项目名称:starter-public-edition-3,代码行数:34,代码来源:preg_error_message.php

示例11: match

 /**
  * @brief Performs a search for the given pattern past the given index.
  * @param $search the pattern to search for
  * @param $index the minimum string index (offset) of a result
  * @param $matches a reference to the return location of the match groups
  * @return the index or false if no match is found.
  */
 public function match($search, $index, &$matches)
 {
     $r = false;
     // return value
     if (isset($this->cache[$search])) {
         $a = $this->cache[$search];
         if ($a === false) {
             return false;
         }
         // no more results
         $r = $a[0];
         $matches = $a[1];
         assert($matches !== null);
         if ($r >= $index) {
             // cache is good!
             return $r;
         }
     }
     // cache not set, or out of date, we have to perform the match
     if (!($ret = preg_match($search, $this->string, $matches_, PREG_OFFSET_CAPTURE, $index))) {
         if ($ret === false && LUMINOUS_DEBUG) {
             throw new Exception('preg_match returned false for pattern: "' . $search . '", with code: ' . LuminousUtils::pcre_error_decode(preg_last_error()));
         }
         $this->cache[$search] = false;
         return false;
     }
     $r = $matches_[0][1];
     // strip the offsets from the match_groups
     foreach ($matches_ as $i => &$v) {
         $v = $v[0];
     }
     $this->cache[$search] = array($r, $matches_);
     $matches = $matches_;
     return $r;
 }
开发者ID:nwhite89,项目名称:Toxic-Designs,代码行数:42,代码来源:strsearch.class.php

示例12: tokenize

 /**
  * Tokenizes string.
  * @param  string
  * @return array
  */
 public function tokenize($input)
 {
     preg_match_all($this->re, $input, $tokens, PREG_SET_ORDER);
     if (preg_last_error()) {
         throw new RegexpException(NULL, preg_last_error());
     }
     $len = 0;
     $count = count($this->types);
     foreach ($tokens as &$match) {
         $type = NULL;
         for ($i = 1; $i <= $count; $i++) {
             if (!isset($match[$i])) {
                 break;
             } elseif ($match[$i] != NULL) {
                 $type = $this->types[$i - 1];
                 break;
             }
         }
         $match = array(self::VALUE => $match[0], self::OFFSET => $len, self::TYPE => $type);
         $len += strlen($match[self::VALUE]);
     }
     if ($len !== strlen($input)) {
         list($line, $col) = $this->getCoordinates($input, $len);
         $token = str_replace("\n", '\\n', substr($input, $len, 10));
         throw new CompileException("Unexpected '{$token}' on line {$line}, column {$col}.");
     }
     return $tokens;
 }
开发者ID:Richmond77,项目名称:learning-nette,代码行数:33,代码来源:Tokenizer.php

示例13: _preg_error

 private function _preg_error()
 {
     switch (preg_last_error()) {
         case PREG_INTERNAL_ERROR:
             echo 'PREG_INTERNAL_ERROR';
             break;
         case PREG_BACKTRACK_LIMIT_ERROR:
             echo 'PREG_BACKTRACK_LIMIT_ERROR';
             break;
         case PREG_RECURSION_LIMIT_ERROR:
             echo 'PREG_RECURSION_LIMIT_ERROR';
             break;
         case PREG_BAD_UTF8_ERROR:
             echo 'PREG_BAD_UTF8_ERROR';
             break;
             // This is only valid for php > 5.3, not certain how to code around it for unit tests
             //			case PREG_BAD_UTF8_OFFSET_ERROR: echo('PREG_BAD_UTF8_OFFSET_ERROR'); break;
         // This is only valid for php > 5.3, not certain how to code around it for unit tests
         //			case PREG_BAD_UTF8_OFFSET_ERROR: echo('PREG_BAD_UTF8_OFFSET_ERROR'); break;
         default:
             //die("Unknown preg error.");
             return;
     }
     echo "<hr><pre>";
     debug_print_backtrace();
     die;
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:27,代码来源:SimpleTemplate.php

示例14: parse

 public function parse($string)
 {
     $parsed = array();
     switch ($this->function) {
         case self::PREG_MATCH:
             if (@preg_match($this->pattern, $string, $parsed, $this->flags) === false) {
                 X_Debug::w("Invalid pattern (" . preg_last_error() . "): {$this->pattern}");
                 $parsed = array();
             }
             break;
         case self::PREG_MATCH_ALL:
             if (@preg_match_all($this->pattern, $string, $parsed, $this->flags) === false) {
                 X_Debug::w("Invalid pattern (" . preg_last_error() . "): {$this->pattern}");
                 $parsed = array();
             }
             break;
         case self::PREG_SPLIT:
             $parsed = @preg_split($this->pattern, $string, null, $this->flags);
             if ($parsed === false) {
                 X_Debug::w("Invalid pattern (" . preg_last_error() . "): {$this->pattern}");
                 $parsed = array();
             }
             break;
         default:
             X_Debug::e("Invalid function code provided: {$this->function}");
     }
     return $parsed;
 }
开发者ID:google-code-backups,项目名称:vlc-shares,代码行数:28,代码来源:Preg.php

示例15: beforeBlockParse

 /**
  * Single block pre-processing.
  * @param  TexyBlockParser
  * @param  string
  * @return void
  */
 public function beforeBlockParse($parser, &$text)
 {
     // autoclose exclusive blocks
     $text = preg_replace('#^(/--++ *+(?!div|texysource).*)$((?:\\n.*+)*?)(?:\\n\\\\--.*$|(?=(\\n/--.*$)))#mi', "\$1\$2\n\\--", $text);
     if (preg_last_error()) {
         throw new TexyPcreException();
     }
 }
开发者ID:jiripudil,项目名称:texy,代码行数:14,代码来源:TexyBlockModule.php


注:本文中的preg_last_error函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。