"/\r\n?/" => "\n", # unix newlines
"/ +\n/" => "<br />", # trailing spaces for hard line break
"/\n/" => "</p>\n<p>", # newlines start paragraphs
- '/\b_(\w+)_\b/' => '<em>$1</em>', # italic
- '/\b\*(\w+)\*\b/' => '<strong>$1</strong>', # bold
+ '/_(?<!\w_)(.+?)_(?!\w)/' => '<em>$1</em>', # italic
+ '/\*(?<!\w\*)(.+?)\*(?!\w)/' => '<strong>$1</strong>', # bold
];
$html = preg_replace(array_keys($markup), array_values($markup), htmlspecialchars($input));
return "<p>$html</p>";