简体   繁体   English

图片和超级链接已替换为说明

[英]image and hyper links replaced in description

I have a search form, in which a user enters a keyword and it displays the results with the keyword in description as highlighted text, for highlighting, i have used another class on that keyword. 我有一个搜索表单,在该表单中,用户输入一个关键字,并在关键字说明中以高亮文本形式显示该关键字的结果,为了突出显示,我在该关键字上使用了另一个类。 problem is that, if there is a keyword in some hyperlink or in some <img> tag , it also applies that class there that causes the image load failure and links are not working. 问题是,如果在某些hyperlink或某些<img> tag有一个关键字,它也会在该类中应用该类,从而导致图像加载失败并且链接不起作用。

That is how i am fetching my results and highlighting them if there is any keyword. 这就是我获取结果并突出显示它们(如果有任何关键字)的方式。

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 />
<? }
}

is there any way that it skips the html tags from replacing? 有什么办法可以跳过替换的html标签吗?

@torando @托兰多

the output is shown like this 输出显示如下

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM