停止DOMXPath从转换的特殊字符评价

问题描述 投票:0回答:1

如果你运行这个DOMXPath评估对有特殊字符的URL(我知道不是技术上有效的URL,但有些网站有他们无论如何):

$a = '<a href="http://example.org/diseño"></a>';
$path = new DOMXPath( @DOMDocument::loadHTML( $a ) );
$href = $path->evaluate( 'string(//a/@href)' );

var_dump( $href );
// http://example.org/diseño

是否有一种方式来获得与“正确的” href字符串 - 如在特殊字符?

http://example.org/diseño

或DOMXPath实际工作正常,因为URL中不能有特殊字符吗?如果是这样,什么是从包含特殊字符的字符串得到HREF最干净的方法吗?

php html html5
1个回答
0
投票

您可以直接从编码的XPath的返回值...

echo utf8_decode($href);

这使...

http://example.org/diseño
© www.soinside.com 2019 - 2024. All rights reserved.