I am relatively new to php, and hope someone can help me with a replace regex, or maybe a match replace I am not exactly sure.
I want to automatically bold the (seco
You could use preg_split to split the text at the matches, apply the modifications, and then put everything back together:
$parts = preg_split('/(example)/', $str, 7, PREG_SPLIT_DELIM_CAPTURE);
if (isset($parts[3])) $parts[3] = ''.$parts[3].'';
if (isset($parts[7])) $parts[7] = ''.$parts[7].'';
if (isset($parts[13])) $parts[13] = ''.$parts[13].'';
$str = implode('', $parts);
The index formula for the i-th match is index = i · 2 - 1.