0

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;
?>
2
Contributors
3
Replies
5
Views
4 Years
Discussion Span
Last Post by diafol
0

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.

0

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;
?>
0

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');
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.