久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      php怎么刪除html注釋

      PHP中可使用preg_replace()函數(shù)配合正則表達式來刪除html注釋,該函數(shù)可以執(zhí)行一個正則表達式的搜索和替換;具體語法格式“preg_replace('#<!–[^![]*?(?<!//)–>#','',字符串)”。

      php怎么刪除html注釋

      本教程操作環(huán)境:windows7系統(tǒng)、PHP7.1版,DELL G3電腦

      php刪除html注釋的方法

      首先比較基礎(chǔ)的是:

          $a = '<!--ceshi-->ceshi';     $a = preg_replace('#<!--.*-->#' , '' , $a);     var_dump($a);

      上面的代碼會輸出ceshi。

      但是如果是下面的字符串的話,就不能達到我們希望的效果了

          $a = '<!--ceshi-->ceshi<!--ceshi-->';     $a = preg_replace('#<!--.*-->#' , '' , $a);     var_dump($a);

      于是我們就把匹配規(guī)則改成如下的格式

      preg_replace('#<!--.*?-->#' , '' , $a);

      但是在html中如果有<!--[if lt IE 9]>ceshi<![endif]-->這樣的代碼的話是不能去掉的,所以我們需要改進匹配規(guī)則,改成以下的格式

      preg_replace('#<!--[^![]*?-->#' , '' , $a);

      又接著如果html中有<script><!--ceshi//--></script>的代碼,我們又需要改一下我們的匹配規(guī)則了,改成了以下格式

      preg_replace('#<!--[^![]*?(?<!//)-->#' , '' , $a);

      這樣的話我基本上就去掉了我需要去掉的html的注釋了!

      推薦學(xué)習(xí):《PHP視頻教程》

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號