eval.in

Paste #2889

PHP — PHP 5.4.6, pasted 1 year ago

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<?php
	$phrases = array("New York NY","York NY","Wyoming MI","Wyoming Minnesota");
	$string = ("I live in York NY");
	$matches = array();
	foreach ( $phrases as $phrase ) {
		$phrase = preg_quote($phrase, '/');
		if (preg_match("/\b$phrase\b/i", $string)) {
			$matches[] = $phrase;
		}
	}
	echo "<pre>";
	print_r($matches);

?>

Program Output

<pre>Array
(
    [0] => York NY
)

OK (0.004 sec real, 0.005 sec wall, 13 MB, 56 syscalls)

Fork