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

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

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.

THANK YOU FOR YOUR REPLY DIAFOL, NOT WORKING PLEASE HAVE LOOK

<?php


$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 for diafol

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');
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.