PHP - htmlspecialchars 函式



語法

string htmlspecialchars ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 
   [, string $encoding = ini_get("default_charset") [, bool $double_encode = true ]]] )

定義和用法

它用於將特殊字元轉換為 HTML 實體

返回值

它返回轉換後的字串。

引數

序號 引數及描述
1

string

它包含輸入字串的資訊

2

flags

它包含有關標誌的資訊

3

encoding

這是一個可選引數,用於定義轉換字元時使用的編碼。

示例

試用以下示例

<?php
   $input = htmlspecialchars("<a href='tutorialspoint'>Tutorialspoint</a>", ENT_QUOTES);
   
   echo $input;
?>

這將產生以下結果 - -

<a href='tutorialspoint'>Tutorialspoint</a>
php_function_reference.htm
廣告