Hello **bold** world
如何使用 preg_replace 将其转换为:
Hello <b>bold</b> world
我认为你是这样想的吧?
$input = "Hello **bold** world";
$output = preg_replace("/(\*\*).*?(\*\*/)", "<b></b>", $input);
Hello **bold** world
如何使用 preg_replace 将其转换为:
Hello <b>bold</b> world
我认为你是这样想的吧?
$input = "Hello **bold** world";
$output = preg_replace("/(\*\*).*?(\*\*/)", "<b></b>", $input);
关闭:
$input = "Hello **bold** world";
$output = preg_replace("/\*\*(.*?)\*\*/", "<b>$1</b>", $input);
我相信有一个PHP包可以渲染Markdown。与其自己动手,不如尝试使用已经编写和测试过的现有代码集。
嗯,我想这可能可行
$output = preg_replace('/\*\*(.*?)\*\*/', '<b>$1</b>', $input);
你需要找到所有的序列**something**,然后用粗体标签替换找到的整个序列,并在其内部($1)使用第一个捕获组(表达式中的括号)。
$output = preg_replace("/\*\*(.*?)\*\*/", "<b>$1</b>", $input);