<?php
$str = 'I try both of previous answer (not working for me 😥).
After downloading the last beta, not working too.
After I changed the iOS Deployement target (11.1 -> 14.0) it\'s working
Hope that can help someone 🙏🏽';
$bl = [
'thank you',
'thanks',
'thankyou',
'best regards',
'regards',
'cheers',
'thx',
'thanx',
'appreciated',
'good afternoon',
'buenas tardes',
'hi there',
'good day',
'This is long 😊',
'good morning',
'hope that can help',
'help someone',
];
function regex(array $bl, string $string) {
$m = [];
foreach ($bl as $word) {
preg_match_all('#'.$word.'#i', $string, $matches, PREG_SET_ORDER, 0);
foreach ($matches as $e) {
$m[] = $e[0];
}
}
}
function str(array $bl, string $string) {
$m = [];
foreach ($bl as $word) {
if (stripos($string, $word) !== false) {
$m[] = $word;
}
}
}
// bench
$time = microtime(true);
$i = 10000;
while ($i--) {
str($bl, $str);
}
echo 'stripos: '.round(microtime(true) - $time, 3)."\n";
$time = microtime(true);
$i = 10000;
while ($i--) {
regex($bl, $str);
}
echo 'Regex: '.round(microtime(true) - $time, 3)."\n";
preferences:
22 ms | 402 KiB | 5 Q