Strong from to : only if there is a :

Posted on 2009-05-26
Medium Priority
Last Modified: 2012-05-07
The only problem with this is that it makes text bold even if there is no :

Test it and you will see the problem.
  $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

Question by:hankknight
1 Comment
LVL 48

Accepted Solution

hernst42 earned 2000 total points
ID: 24472920
You could try:
$str = preg_replace('/(^|<p>)([^:<]+):/ims', '\1<strong>\2:</strong>', $str);

Open in new window


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question