Converting named HTML entities to numeric HTML entities

前端 未结 6 1858
半阙折子戏
半阙折子戏 2020-12-08 08:18

Is there a PHP function to convert named HTML entities into their respective numeric HTML entities?

For example:

$str = \"Oggi è un bel&am         


        
6条回答
  •  攒了一身酷
    2020-12-08 08:42

    First use html_entity_decode to get the unencoded version of your source code. If necessary, set the third parameter (encoding) to the proper value.

    Then use utf8_encode on that source code.

    $source_code_without_entities = html_entity_decode($source_code_with_entities);
    $utf8_source_code = utf8_encode($source_code_without_entities);
    

提交回复
热议问题