- array_map: documentation ( source)
- print_r: documentation ( source)
- preg_quote: documentation ( source)
- preg_replace: documentation ( source)
<?php
function highlightWords($content)
{
$arr=array("php", "and sql", "sql");
$arr = array_map(function($v){
return "/\b(" . preg_quote($v, "/") . ")\b/i";
}, $arr);
print_r($arr);
$content=preg_replace($arr, '<a href="#">$1</a>', $content, 1);
return $content;
}
echo highlightWords("This text will highlight PHP and SQL and sql but not PHPRO or MySQL or sqlite");