You 'd be much better off using a regular expression here:
$bolded = preg_replace('/^\d+:\d+\s*-\s*[^:]+/', '<b>$1</b>', $ex);
This matches the pattern ^\d+:\d+\s*-\s*[^:]+
and replaces it with <b>$1</b>
, which really means that the match is placed inside bold tags (use <strong>
for more semanticness, this is just an example).
What does ^\d+:\d+\s*-\s*[^:]+
match?
^ at the start of the string...
\d+ one or more digits -+
: a double colon +---> the time
\d+ one or more digits -+
\s* zero or more whitespace
- a dash
\s* zero or more whitespace
[^:]+ one or more of "not :" -----> the username