-1
I am trying to highlight a certain word in the search as follows:
The user types the word in the search stand out and this 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;
Note that you are using
echo $texto
, instead ofecho $tarjado
.– Inkeliz