- var_export: documentation ( source)
- explode: documentation ( source)
- in_array: documentation ( source)
<?php
function contains($text, $word) {
return in_array($word, explode(' ', $text))
|| in_array($word, explode(chr(160), $text));
}
$tests = [
'How are you?',
'Are you okay?',
'I think you are.'
];
foreach ($tests as $text) {
echo "\n$text evaluates as ";
var_export(contains($text, 'are'));
}