pregMatch() 공개 정적인 메소드

By default this works properly with UTF8 strings. Do not forget to use preg_quote() first on strings that could potentially contain unescaped characters. Note that you still need to add the u modifier (for UTF8) to your pattern yourself. Example: /some(.*)pattern/u
public static pregMatch ( string $pattern, string $subject, integer | null $flags = null, integer | null $offset = null ) : array
$pattern string The pattern to use.
$subject string The string to match.
$flags integer | null
$offset integer | null
리턴 array Result
예제 #1
0
 /**
  * UtilityTest::testPregMatchWithPatternEscape()
  *
  * @covers ::pregMatch
  * @return void
  */
 public function testPregMatchWithPatternEscape()
 {
     $string = 'http://www.example.com/s?q=php.net+docs';
     $res = preg_quote($string);
     $this->assertSame('http\\://www\\.example\\.com/s\\?q\\=php\\.net\\+docs', $res);
     $string = 'http://www.example.com/s?q=php.net+docs';
     $res = preg_quote($string, '/');
     $this->assertSame('http\\:\\/\\/www\\.example\\.com\\/s\\?q\\=php\\.net\\+docs', $res);
     $res = '/a\\s*' . $res . '\\s*z/i';
     $string = 'a ' . $string . ' z';
     $matches = Utility::pregMatch($res, $string);
     $expected = [$string];
     $this->assertSame($expected, $matches);
 }