《PHP實例:php自定義函數轉換html標簽示例》要點:
本文介紹了PHP實例:php自定義函數轉換html標簽示例,希望對您有用。如果有疑問,可以聯系我們。
PHP實戰本文實例講述了php自定義函數轉換html標簽的方法.分享給大家供大家參考,具體如下:
PHP實戰
<?php
/*
* Created on 2016-9-29
*
*/
$orig = "I'll \"walk\" the <b>dog</b> now";
$a = htmlentities($orig);
$b = html_entity_decode($a);
echo $a; // I'll "walk" the <b>dog</b> now
echo $b; // I'll "walk" the <b>dog</b> now
// For users prior to PHP 4.3.0 you may do this:
function unhtmlentities($string)
{
// replace numeric entities
$string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
$string = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $string);
// replace literal entities
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}
$c = unhtmlentities($a);
echo $c; // I'll "walk" the <b>dog</b> now
?>
PHP實戰運行結果如下圖所示:
PHP實戰
PHP實戰更多關于PHP相關內容感興趣的讀者可查看本站專題:《PHP編碼與轉碼操作技巧匯總》、《php面向對象程序設計入門教程》、《PHP數學運算技巧總結》、《PHP數組(Array)操作技巧大全》、《php字符串(string)用法總結》、《PHP數據結構與算法教程》、《php程序設計算法總結》、《php正則表達式用法總結》、及《php常見數據庫操作技巧匯總》
PHP實戰希望本文所述對大家PHP程序設計有所幫助.
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/3168.html