1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| <style type="text/css">
.highlight_word{
background-color: pink;
}
</style>
<?php
// les valeurs...
$keywords ="option";
$url ="http://www.option-culinaire.ch"; // ce site n'existe pas...;-)
$description ="toutes les options que j'aimerais faire fonctionner, l'option binaire ou l'option de ne rien faire";
$nomsite ="Tout savoir sur les options";
// la fonction...
function highlightWords2($string, $keywords)
{
$keywords = explode(' ', $keywords);
foreach ($keywords as $word)
{
$string = str_ireplace($word, '<span class="highlight_word">'.$word.'</span>', $string);
}
return $string;
}
// couper les mots concernés...
$nomsite = highlightWords2(substr($nomsite, 0, 100), $keywords);
$description = highlightWords2(substr($description, 0, 400), $keywords);
$url = highlightWords2(substr($url, 0, 100), $keywords);
// j'affiche le résultat...
echo"
Nomsite : <a href='$url' target='_blank'>$nomsite</a><br >
Description : $description<br >
Url : <a href='$url' target='_blank'>$url</a><br >";
?> |
Partager