douhu2131 2012-09-08 20:28
浏览 44
已采纳

PHP在字符串中检测和拆分html特殊字符代码?

In PHP when i read the Data, lets say the data (chunk of string) is containing HTML Special Character DECIMAL HEX Codes like:
This is a sample string with < œ < and š

What i want is, how to Detect and Split out the Decimal Hex Codes (of any Special Characters) inside a chunk of string?

For example, above string contains:

  • Two Count of <
  • One Count of œ
  • One Count of š

How can i programatically detect it (The OCCURRENCE for any Html Special Characters)?
(Collected results will be better as an Array)

  • 写回答

4条回答 默认 最新

  • douzhigan1687 2012-09-08 20:41
    关注

    I think this is what you are after:

    $s = 'This is a sample string with œ and š';
    
    $pattern = '/\&#x\d+\;/';
    
    preg_match_all($pattern, $s, $matches);   
    
    var_dump( $matches );
    

    This will output:

    array(1) {
      [0]=>
      array(2) {
        [0]=>
        string(7) "œ"
        [1]=>
        string(7) "š"
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试