Hi All, i found this code which is ok but i need this to highlight whole line in colour, for example like:

1. Mr Johan call in office on sunday
2. No More call to johan
3. Johan has Paid All

I am telling the script to start from star and end on star, each line need to be different colour.

this is what i found so far how can we amend this in my way

$word = 'hello';
$sentence = 'hello world';
$sentence = str_ireplace($word,'<span style="background-color:#ffff00;">'.$word.'</span>',$sentence);
echo $sentence;
Member Avatar

I'm assuming these sentences are in an array? If so:

use a foreach loop to run over them. Check for the word within a sentence with stripos and apply the start span and end span tags around the whole sentence - save it back to the array.

foreach($array as $k=>$v){
    if(stripos($v,$word) !== false)$array[$k] = '<span style="background-color:#ffff00;">'.$v.'</span>';

Not tested. Not sure if $array in loop will do it, but if not, you can create a new array or a long string on the fly.



$word = '*1. Mr Johan call in office on sunday*
*2. No More call to johan*
*3. Johan has Paid All*';

foreach($array as $k=>$v){
        if(stripos($v,$word) !== false)$array[$k] = '<span style="background-color:#ffff00;">'.$v.'</span>';}

echo $V;
Member Avatar

It won't because you're not using an array - you've just got one long string.

$word = array('1. Mr Johan call in office on sunday','2. No More call to johan','3. Johan has Paid All');