DomDocument and html entities

前端 未结 4 494
臣服心动
臣服心动 2021-01-03 06:38

I\'m trying to parse some HTML that includes some HTML entities, like ×

$str = \' A × B\';

$do         


        
4条回答
  •  [愿得一人]
    2021-01-03 06:59

    Are you sure the & is being substituted to &? If that were the case, you'd see the exact entity, as text, not the garbled response you're getting.

    My guess is that it is converted to the actual character, and you're viewing the page with a latin1 charset, which does not contain this character, hence the garbled response.

    If I render your example, my output is:

    fullname:  A × B 
    
    href: http://example.com/
    

    When viewing this in latin1/iso-8859-1, I see the output you're describing. But when I set the charset to UTF-8, the output is fine.

提交回复
热议问题