2015-02-11 82 views
1

我有一個有很多html實體的文件。我需要將html實體轉換爲十六進制實體。如何將html實體轉換爲php中的十六進制實體?

例子:&&

是否有HTML的十六進制實體轉換的任何功能?如果不是,哪種方式是實現這一目標的有效和最快的方法?

+0

也許這個問題有幫助: http://stackoverflow.com/questions/7482977/get-hexcode-of-html-entities – Catshinski 2015-02-11 14:38:48

回答

0

首先,「十六進制實體」是具有以Unicode碼點表示的字符的實體。所有Unicode字符都可以用Unicode代碼表示爲實體;在HTML中,一些可以用一個名字來表示,而不是。

在HTML實體,其有一個預定義的名字的名單很長:http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Character_entity_references_in_HTML

如果您有在HTML實體使用簡寫名稱已經轉換後的文本,那麼你唯一的選擇就是做一個搜索和替換。不用說,這可能是相當計算量的。該代碼是這樣:

<?php 
$str = 'Hello &amp; world! &quot;'; 

$find = ['&amp;', '&quot;']; //.. Complete the table with the entire list 
$replace = ['&#x00026;', '&#x00022;']; // ... Complete this list too 
$str = str_replace($find, $replace, $str); 
echo $str; 
?> 

然而,這可以很慢

相關問題