I'm trying to preg_match $text for specific words, defined in an array. $text = "PHP is a programming language of choice";
$text = "This is a function written in a programming language called PHP.";
$words = array("/java/", "/PHP/", "/html/");
for ($i = 0; $i < count($words); $i++)
{
preg_match($words[$i], $text, $matches);
}
The problem with tis is that it returns 3 arrays, of which only the second one is a match, and the other 2 arrays are empty. The result is that I get notice error on my echo page because the 1st and 3rd arrays are empty. if I want the text to be searched for the first matching result, whether it is java, PHP or html, then stop (if possible) and echo/return the result, how will I do that? Perhaps preg_match is not to be used here but instead something like substr?