0

我有一个搜索表单,用户在其中输入关键字,并将结果与​​描述中的关键字显示为突出显示的文本,为了突出显示,我在该关键字上使用了另一个类。问题是,如果 somehyperlink或 some中有关键字<img> tag,它也会应用那个导致图像加载失败和链接不起作用的类。

这就是我获取结果并在有任何关键字时突出显示它们的方式。

if($_GET['key']){ 
        $key = $_REQUEST['key'];
$sql = "select * from tbl_feed WHERE title LIKE '%$key%' OR description like '%$key%'";
$rs  = $dbFun->selectMultiRecords($sql);
for($j=0;$j<count($rs);$j++){
        $title= mb_convert_encoding($rs[$j]['title'], "iso-8859-1","auto");
        $desc   = mb_convert_encoding($rs[$j]['description'],"iso-8859-1","auto");
        ?>
        <?php
      for($i = 0; $i < sizeof($arrKeywords); $i++){
                        $title = str_ireplace($arrKeywords[$i], "<font class=\"highlight\">" . $arrKeywords[$i] . "</font>", $title);
                        $desc = str_ireplace($arrKeywords[$i], "<font class=\"highlight\">" . $arrKeywords[$i] . "</font>", $desc);
                    }
      ?>

<a href="<?=$rs[$j]['link']?>" target="_blank"><strong><?=$title?></strong></a><BR />
<?=$rs[$j]['pubdate']?><BR /><BR />
<?=$desc?><BR /><BR /><BR />
<? }
}

有什么方法可以跳过html替换标签?

4

1 回答 1

0

@托兰多

输出显示如下

Sub-header image reference:  Newsroom Main image:  35 Million Directors project will help inspire more travellers around the world to come and explore canada. [newsroom_additional_information]   35 Million Directors project will help inspire more travellers around the world to come and explore canada. Additional Information:  <p> <strong>Previous five news releases</strong></p> <p> <a href="http://en-corporate.canada.travel/content/news_release/q1-2012-international-market-insights-report">Q1 2012 International Market Insights. </a></p> <p> <a href="http://en-corporate.canada.travel/content/news_release/rendez-vous-canada-tiac-prime-strategies">Canadian Tourism Commission business notice: Rendez-vous canada event management.</a></p> <p> <a href="http://en-corporate.canada.travel/content/news_release/rendez-vous-canada-2012-edmonton">Rendez-vous canada 2012: ready to rev up big business for tourism.</a></p> <p> <a href="http://en-corporate.canada.travel/content/news_release/signature-experiences-collection-sec-48-businesses">Outside the ordinary in canada.</a></p> <p> <a href="http://en-corporate.canada.travel/content/news_release/signature-experiences-collection-global-marketing-platform">Signature Experiences Collection® members make international debut as Canadian Tourism Commission launches new global marketing platform</a></p> read more
于 2012-09-18T10:27:38.787 回答