2009-08-08 htmlentities() 和 html_entity_decode()

htmlentities() 和 html_entity_decode()

htmlentities()
http://www.php.net/manual/en/function.htmlentities.php

功能上很簡單, 就是將 < 變作 &lt;
當然, 還有其他的entities, 可以參考: http://www.w3schools.com/tags/ref_entities.asp
主要是給使用者輸入的 entities 會 escape, 輸出的時候便可以直接使用

另一方面,

我的一個project 會使用 file_get_content() 來使用 http 下載某些相關的網頁,
然後抽取其中內容顯示
但 <title> 中的entities 不會被瀏覽器 decode, 所以便會使用到:

html_entity_decode()
http://www.php.net/manual/en/function.html-entity-decode.php

其實是 htmlentities() 的相反

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <h4> <h3>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options