<?php
$text = "This is my test string that needs to be matched and not the test keywords following it";
if (preg_match("/(.*?)test/", $text, $match)) {
print_r($match);
}
if (preg_match("/^(.*?)test/", $text, $match)) {
print_r($match);
}
if (preg_match("/(.*)test/", $text, $match)) {
print_r($match);
}
?>
Array
(
[0] => This is my test
[1] => This is my
)
Array
(
[0] => This is my test
[1] => This is my
)
Array
(
[0] => This is my test string that needs to be matched and not the test
[1] => This is my test string that needs to be matched and not the
)