Texy\Regexp::match PHP Method

match() public static method

Performs a regular expression match.
public static match ( $subject, $pattern, $flags, $offset ) : mixed
return mixed
    public static function match($subject, $pattern, $flags = 0, $offset = 0)
    {
        $empty = $flags & self::ALL ? [] : NULL;
        if ($offset > strlen($subject)) {
            return $empty;
        }
        $reFlags = $flags & self::OFFSET_CAPTURE ? PREG_OFFSET_CAPTURE : 0;
        if ($flags & self::ALL) {
            $res = preg_match_all($pattern, $subject, $m, $reFlags | PREG_SET_ORDER, $offset);
        } else {
            $res = preg_match($pattern, $subject, $m, $reFlags, $offset);
        }
        if (preg_last_error()) {
            // run-time error
            trigger_error(@self::$messages[preg_last_error()], E_USER_WARNING);
        } elseif ($res) {
            return $m;
        }
        return $empty;
    }

Usage Example

Esempio n. 1
0
 /**
  * @return void
  */
 public function process(Texy\BlockParser $parser, $content, Texy\HtmlElement $el)
 {
     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
         $mod = NULL;
         if ($mx = Regexp::match($s, '#' . Texy\Patterns::MODIFIER_H . '(?=\\n|\\z)#sUm', Regexp::OFFSET_CAPTURE)) {
             list($mMod) = $mx[1];
             $s = trim(substr_replace($s, '', $mx[0][1], strlen($mx[0][0])));
             if ($s === '') {
                 continue;
             }
             $mod = new Texy\Modifier();
             $mod->setProperties($mMod);
         }
         $res = $this->texy->invokeAroundHandlers('paragraph', $parser, [$s, $mod]);
         if ($res) {
             $el->insert(NULL, $res);
         }
     }
 }
All Usage Examples Of Texy\Regexp::match