dongsetan3216 2013-07-24 15:40
浏览 136
已采纳

PHP函数将HEX字符代码转换为等效显示

I am working on some PHP code to identify HEX character codes in a string and convert them to their "as seen on screen" equivalent. Mainly, there HEX codes are for accented characters like é, ç and so on.

For example, I am receiving a string like this:

$str = "caf&#xe9s"; - NOTE there is a semicolon after the 9 (i had to remove it to stop this text editor converting it!

The HEX part of the string is &#xe9 (again with semicolon at end) - and I am needing to convert that to its "as seen on screen" equivalent, in this case "é". So the converted string would be "cafés".

The following PHP code works, but I have to write one for each HEX code, and there are scores of them.

$keywords = str_replace("&#xe9","é",$keywords); [again the needle part has a semicolon]

Can anyone suggest an existing PHP function that can scan any string for known HEX codes and convert it to the display equivalent?

I am working in UTF8 otherwise.

Thanks for your consideration, sorry if my terminology sounds amateur.

James

  • 写回答

1条回答 默认 最新

  • dqkkrt8860 2013-07-24 15:44
    关注

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

    This will convert HTML entities into their associated char

    $keywords = html_entity_decode($keywords);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号