Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/02/2011, 11:14
danicss
 
Fecha de Ingreso: febrero-2011
Mensajes: 37
Antigüedad: 13 años, 2 meses
Puntos: 2
Buscar palabras y ponerlas en negrita

Hola,

me gustaría hacer lo siguiente, tengo dos variables, una con un texto y otra con palabras sueltas, lo que quiero hacer es comprobar si en el texto existen las palabras que están en la otra variable, si es así, que se pongan automáticamente en negrita... he estado haciendo pruebas y no me sale...

Código:
<?php 

$texto='
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
';

$palabras='Lorem dummy simply';
$pal = explode(" ", $palabras);
$textos = explode(" ", $texto);

for($i=0;$i<count($textos);$i++) {
for($x=0;$x<count($pal);$x++) {
if($textos[$i]==$pal[$x]){echo '<strong>'.$textos[$i].'</strong><br />';}else{echo $textos[$i].'<br />';}
}
}

?>
se me repiten las palabras muchas veces, ya que lo tengo dentro del bucle, pero claro... sino, no va.., ¿alguien podría echarme una mano?.