【发布时间】:2015-08-31 15:01:27
【问题描述】:
我正在结果页面上创建搜索词的亮点。
这是我现在使用的:
$resmessage = preg_replace ( '/' . preg_quote ( $searchword, '/' ) . "/iu", '<span class="searchword" >' . $searchword . '</span>', $resmessage );
但是当单词是附件上的标题名称时,会破坏布局。
示例文本:
test ok /n[attachment=1]test-2.png[/attachment]
结果:
test ok test-2.png" title="test-2.png" rel="lightbox[imagelink2]"> test-2.png" style="max-height:800px;" alt="" />
所以我想在搜索词之前排除任何字符。 这样做的正则表达式是什么,我尝试了很多选项。
【问题讨论】:
-
none character是什么意思?空格?...或者$searchword是什么,所以我可以在本地运行测试。 -
like ] searchword = test
-
那么,如果空格尾随搜索词替换它?示例输出应该是
<span class="searchword" >test</span>ok /n[attachment=1]test-2.png[/attachment],对吗? -
或者粗体是最好的方式,所以你有:[b]test[/b]ok n[attachment=1]test-2.png[/attachment],后面一定要有空格用于查找单词的搜索词
标签: php regex preg-replace bbcode