Q:

preg_replace, ignore when space added

I have this simple piece of code to turn *text* into <strong>text</strong>.
This all works great, but now I also want to be able to use * for making lists, like:
* item 1
* item 2
* item 3

This will obviously not work with my current code. Is there a way to change the code so that * (with a space next to them) are ignored?
This is my current code:
$content = preg_replace('#\*(.*?)\*#is', '<strong>$1</strong>', $content);

EDIT:
Sorry, I might have been a bit unclear with my example.
So this is the original input:
*test*

* test
* test
* test

   *test*

This should be formatted as:
<strong>test</strong?

* test
* test
* test

   <strong>test</strong>

So bassicly *test* should show up as <strong>test</strong>, unless there is a space right next to the *.
So * test, will remain * test
It's a little like the formatting used in basecamp

A:

You may use [^\s] to match any non-space character (you could also use\b to get a word boundary, but you would have issues with non-word characters). Your code would be like this:
$content = preg_replace('#\*([^\s\*]([^\*]*[^\s\*])?)\*#is', '<strong>$1</strong>', $content);

Cheers,

