Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

Strong from to : only if there is a :

The only problem with this is that it makes text bold even if there is no :

Test it and you will see the problem.
<?php
  $str = '
	This should be bold: this should not be bold
	<p>Intro text: this is a test.</p>  
	<p>Hello world: How are you?</p>   
	<p>This text should not be bold because there is no colon. Test 123.</p>   
	<p>Foobar: Zooph.</p>';
 
  $str = preg_replace('/(^|<p>)([^:]+):/ims', '\1<strong>\2:</strong>', $str);
  echo $str;
  
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of hernst42
hernst42
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial