- print_r: documentation ( source)
- preg_match_all: documentation ( source)
- preg_replace: documentation ( source)
<?php
$sentence = "foo_foo_foo foo-foo_foo";
if (preg_match_all("/(?<![^\W_])foo(?![^\W_])/i", $sentence, $matches)) {
print_r($matches[0]);
}
echo PHP_EOL . preg_replace("/(?<![^\W_])foo(?![^\W_])/i", "YES", $sentence);