Reputation: 8492
I have a PHP page that is reading text stored in a MYSQL database table. The text might look something like this
Bob: Hi blah blah
(Bob walking around)
Fred Johnson: blah blah blah
Bob: Something something: something
I want to do a preg_replace to bold everything that comes before the first colon in each line. So in this situation only the names would be bold and on that last line "Something something" would not be bold
What I have now bolds everything on each line that comes before any colon
$reg='(.*\w:)';
$text = preg_replace("/".$reg."/", "<b>\${1}</b>", $text);
Upvotes: 3
Views: 130
Reputation: 226296
The ^
symbol is used to match the beginning of a line. Prepend that to the beginning of your regex and it will assure that the match starts at the beginning of the current line :-)
Upvotes: 0