pregMatchAll() public static method

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 pregMatchAll ( string $pattern, string $subject, integer $flags = PREG_SET_ORDER, integer | null $offset = null ) : array
$pattern string The pattern to use.
$subject string The string to match.
$flags integer
$offset integer | null
return array Result
Ejemplo n.º 1
0
 /**
  * UtilityTest::testPregMatchAll()
  *
  * @covers ::pregMatchAll
  * @return void
  */
 public function testPregMatchAll()
 {
     $string = 'D-81245 München';
     preg_match_all('/(*UTF8)([\\w+])-([a-z0-9]+)\\s+\\b([\\w\\s]+)\\b/iu', $string, $matches, PREG_SET_ORDER);
     $expected = [[$string, 'D', '81245', 'München']];
     $this->assertSame($expected, $matches);
     // we dont need the utf8 hack:
     $matches = Utility::pregMatchAll('/([\\w+])-([a-z0-9]+)\\s+\\b([\\w\\s]+)\\b/iu', $string);
     $this->assertSame($expected, $matches);
 }