使用PHP模拟“自定义引号”

时间:2014-02-16 02:15:13

标签: php css html

我不知道它叫什么,所以我只想使用术语自定义引号,我的意思是像StackOverflow的样式,你使用星号来使事情变粗,**Like &nbsp;this**和它会结束像这样,这可能会有所帮助 <span style='font-weight: bold;'>Like this</span> ...我查了一下PHP的preg_match,但我不确定这是不是正确的事情。

<小时/>
简单来说:

我如何获得:

-Text-

变成:

<span style='color: red;'>Text</span>

2 个答案:

答案 0 :(得分:1)

使用PHP Markdown之类的内容。安装完成后,您可以执行以下操作:

$my_text = "-Text-";
use \Michelf\Markdown;
$my_html = Markdown::defaultTransform($my_text);

答案 1 :(得分:-1)

$message = 'Testing this **quote**';
$search = '/\*\*(.*?)\\*\*/';
$replace = '<span style="font-weight: bold;">\\1</span>';
echo preg_replace($search, $replace, $message);