I've spent countless days trying to figure this out... I have a list of names I want to check for on my page. How can I check for these in a string. The last thing I tried was str_word_count
$members = "anne, barb, max"
print_r(str_word_count($members, 1));
Obviously that just returns an array of the $members variable. I want to check for the variables in my file and return which names were found.
I know this is probably a super easy question but, as my username suggests, I am a SuperN00b.
index.php
$data = file_get_contents('page.php');
$names = ['simon', 'jeff'];
foreach($names as $name)
{
if(strpos($data, $name))
{
echo $name . " Is in file! <br>";
}
}
page.php
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
anna barry simon puma george jessica michael
jamil adil john jeff
</body>
</html>
Output of this specific code
simon Is in file!
jeff Is in file!
Is this along the lines of what you were looking for?