How can I get the next word after pregmatch with PHP.
For example, If I have a string like this:
"This is a string, keyword next, some more text. keyword next-word."
I want to use a preg_match
to get the next word after “keyword”, including if the word is hyphenated.
So in the case above, I want to return “next” and ”next-word”
I’ve tried :
$string = "This is a string, keyword next, some more text. keyword next-word.";
$keywords = preg_split("/(?<=\keyword\s)(\w+)/", $string);
print_r($keywords);
Which just returns everything and doesn’t seem to work at all.
Any help is much appreciated.