I have the following PHP code:
<?php
$keys= "Nuevo Antivirus, este es llamado Anti-AllSafe";
// Encontramos esas "palabras clave"
if (strpos($keys, 'Anti') !== false) { $encontrado = true; }
if ($encontrado) {echo "";} // Justo aquí es donde muestre las coincidencias: "Antivirus y Antivirus-AllSafe"
else {echo ' Sin parecidos';}
?>
What I want to do is that no matter how many times the word Antivirus appears in all the text, it will autocomplete, example:
Anti - Autocomplete in: Antivirus
And the second match completes:
Anti is completed in: Anti-AllSafe
In short, it is the continuity of that word in pass to the 'keyword'. I appreciate if you can help me with this problem, I don't know if I'm doing it wrong or if there is a way to make it more effective,
You could create a regular expression to search for all words that contain the
clave
RegExp Description
[^\s,.]*
: zero or more matches of characters other than empty characters (\s
), comma (,
) and period (.
)(KEY)
: "key" which must contain1
i
: flag to indicate that it is not case sensitive ( case insensitive ).Example:
Demo
References:
You can use
str_replace
like this: