如何解析标点符号并用PHP中的html标记替换

I was wondering if there is a way to take a string like

$string = "Look at *me* because I am bold";

and replace the asterisks with tags so the string would be

echo $string; //"Look at <bold>me</bold> because I am bold"

Try $string = preg_replace('~\*(.*?)\*~','<bold>$1</bold>',$string);

Edit: Appended the semicolon I forgot.

Don't roll your own, you'll quickly end up with a bunch of special cases and loads of trouble. Just get yourself a proper Markdown library and move onto something more important.