I'm trying to highlight a particular word in the search as follows:
The user types in the search the word highlight and that word would be highlighted in the text. For this, I tried with the 02 codes below, but I could not:
First code:
$buscar = "destacar";
$texto = "Lorem ipsum dolor sit amet, consectetur destacar adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
$tarjado = preg_replace("/($buscar)/i", "<span style='background-color:#FF0;color:#F00'>\1</span>", $texto);
echo $texto;
Second code:
$buscar = "destacar";
$texto = "Lorem ipsum dolor sit amet, consectetur destacar adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
$tarjado = preg_replace( sprintf( '/\b(%s)\b/i', is_array( $buscar ) ? implode( '|', $buscar ) : $buscar ), '<span class="font-weight: bold">$1</span>', $texto );
echo $texto;