You better do it with JS after the page loads it with needed encoding:
function paint_keys( str_to_replace , words ){
temp_reg = str_to_replace;
if( /\s/g.test( temp_reg ) ) temp_reg = temp_reg.split( " " ); // Breaking our searching keywords into an array;
else return words.split( temp_reg ).join( "<span class='painted'>" + temp_reg + "</span>" );
for( z = 0 ; z < temp_reg.length ; z++ ){
if( temp_reg[ z ] != "" ) words = words.split( temp_reg[ z ] ).join( "<span class='painted'>" + temp_reg[ z ] + "</span>" );
}
return words;
}
Of course, you can replace the <span class='painted'>" + temp_reg + "</span>
to whatever you need.
If you need it to be done by php only - use the principle of breaking the keys to array by explode( "\s" , $words );
- that will give you an array of symbols only and then loop to replace the string for each word in the array.