I have a chatlog file that looks like this (name represents screenames and text is their chat string)
name: some text
name2: more text
name: text
name3: text
I want to color all names up to the : red.
For example: <font color=red>myname:</fontcolor> hello
How would I do this?
I’m not sure why, but this code colors everything after the colon
echo preg_replace('/(.*?):/', "<font color=#F00>$1</font>:", $output);
A correct answer to this question has been provided previously:
Look at the second answer:
PHP: insert text up to delimiter
In addition, your implementation is wrong, look at the regular expression it should start with ^ :
Should be: