五月综合缴情婷婷六月,色94色欧美sute亚洲线路二,日韩制服国产精品一区,色噜噜一区二区三区,香港三级午夜理伦三级三

您現(xiàn)在的位置: 365建站網(wǎng) > 365文章 > HTML轉(zhuǎn)換為文本和文本轉(zhuǎn)HTML函數(shù)實例

HTML轉(zhuǎn)換為文本和文本轉(zhuǎn)HTML函數(shù)實例

文章來源:365jz.com     點擊數(shù):440    更新時間:2018-01-11 10:05   參與評論
HTML轉(zhuǎn)換為文本:

/**
*  HTML轉(zhuǎn)換為文本
*
* @param    string  $str 需要轉(zhuǎn)換的字符串
* @param    string  $r   如果$r=0直接返回內(nèi)容,否則需要使用反斜線引用字符串
* @return   string
*/
if ( ! function_exists('Html2Text'))
{
    function Html2Text($str,$r=0)
    {
        if($r==0)
        {
            return SpHtml2Text($str);
        }
        else
        {
            $str = SpHtml2Text(stripslashes($str));
            return addslashes($str);
        }
    }
}

function SpHtml2Text($str)
{
$str = preg_replace("/<sty(.*)\\/style>|<scr(.*)\\/script>|<!--(.*)-->/isU","",$str);
$alltext = "";
$start = 1;
for($i=0;$i<strlen($str);$i++)
{
if($start==0 && $str[$i]==">")
{
$start = 1;
}
else if($start==1)
{
if($str[$i]=="<")
{
$start = 0;
$alltext .= " ";
}
else if(ord($str[$i])>31)
{
$alltext .= $str[$i];
}
}
}
$alltext = str_replace(" "," ",$alltext);
$alltext = preg_replace("/&([^;&]*)(;|&)/","",$alltext);
$alltext = preg_replace("/[ ]+/s"," ",$alltext);
return $alltext;
}

文本轉(zhuǎn)HTML:

/**
*  文本轉(zhuǎn)HTML
*
* @param    string  $txt 需要轉(zhuǎn)換的文本內(nèi)容
* @return   string
*/
if ( ! function_exists('Text2Html'))
{
    function Text2Html($txt)
    {
        $txt = str_replace("  ", " ", $txt);
        $txt = str_replace("<", "&lt;", $txt);
        $txt = str_replace(">", "&gt;", $txt);
        $txt = preg_replace("/[\r\n]{1,}/isU", "<br/>\r\n", $txt);
        return $txt;
    }
}




如對本文有疑問,請?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會為你解答!! 點擊進入論壇

發(fā)表評論 (440人查看,0條評論)
請自覺遵守互聯(lián)網(wǎng)相關(guān)的政策法規(guī),嚴禁發(fā)布色情、暴力、反動的言論。
昵稱:
最新評論
------分隔線----------------------------

其它欄目

· 建站教程
· 365學習

業(yè)務(wù)咨詢

· 技術(shù)支持
· 服務(wù)時間:9:00-18:00
365建站網(wǎng)二維碼

Powered by 365建站網(wǎng) RSS地圖 HTML地圖

copyright © 2013-2024 版權(quán)所有 鄂ICP備17013400號