好的,我有一个输出一些文本的字符串。
~ Terraces
The apartment has two large terraces. Main terrace (30m2) is accessible from the living room, is fitted with a large wooden table with 6 armchairs and large comfortable wooden sunbeds. The views from here are amazing, you can admire incredible sea views but also you have a fascinating view of La Concha, the striking mountain that sits behind Marbella. Second terrace (14m2) is accessible from the kitchen.
我唯一想做的就是制作像这样的模式 ~ string 转换为 string。更具体地说,是为了摆脱 ~、空格和将文本设为粗体。
我创建了这个函数:
function bold($var) {
$var = preg_replace('/~\s(.*?)/', '<strong>$1</strong>', $var);
return $var;
}
该函数删除了〜但不会使文本变为粗体。为什么?更奇怪的是,如果我在强标记之间插入一些内容,我会得到粗体文本,然后是我想要非粗体的文本,即使它们'位于相同的标签中。
简单说明一下...$var 是整个字符串,就像上面示例中的那样。
最佳答案
我相信你需要这个:
$var = preg_replace('/~\s*(\S+)/', '<strong>$1</strong>', $var);
关于php - php将word设置为粗体的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20172249/