查看: 933|回复: 3
|
php的highlight function
[复制链接]
|
|
各位,我想请问一下,在php,如何将一个从资料库query出来的data,把其中的关键字眼highlight,但并不包括html tag。比如说,要highlight的是把关键字变粗(strong)
$string="<p><i>This is the testing path</i></p>";
$keyword="i"; //这是user输入的
$answer = highlight($string,$keyword);
function highlight($string,$keyword)
{
//请教这里如何把string里头的"i"highlight(变粗)?但不包括<i>和</i>
return result
}
而最终的$answer所存的内容为:<p><i>Th<strong>i</strong>s <strong>i</strong>s the test<strong>i</strong>ng path</i></p>,而不是:Th<strong>i</strong>s <strong>i</strong>s the test<strong>i</strong>ng path
我试过用SEO algorithm 来做,(google的方法),只能把$string 里头的html tag拿掉,但并不能保存原有的tag。各位看得明白吗?帮帮忙,感激不尽 |
|
|
|
|
|
|
|

楼主 |
发表于 29-8-2006 09:52 AM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 1-9-2006 02:59 PM
|
显示全部楼层
各位,没人给我任何的指导吗?我已经找了好久了,谢谢 |
|
|
|
|
|
|
|
发表于 15-12-2006 04:10 PM
|
显示全部楼层
试用看htmlspecialchars()或 htmlentities()
<?php
$str = "A 'quote' is <b>bold</b>";
echo htmlentities($str);
echo htmlentities($str, ENT_QUOTES);
?> |
|
|
|
|
|
|
| |
本周最热论坛帖子
|