使用特殊字符扩展变量时出错

Error in Exploding variables with Specail Characters

$html = file_get_contents('abc.com/abc');
// create document object model
$dom = new DOMDocument();
// load html into document object model
@$dom->loadHTML($html);
// create domxpath instance
$xPath = new DOMXPath($dom);
// get all elements with a particular id and then loop through and print the href attribute
$elements = $xPath->query("//*[@class='f16']");
foreach ($elements as $e) {
  $str = $e->nodeValue;
}
$values = explode("A", $str);
echo $values[0];

Returns "Data1 Â Data2 Â Data 3"

但它工作正常,

$values = explode("Â", "Data1 Â Data2 Â  Data 3");
echo $values[0];

Returns "Data1"

如何解决这个问题?

如果您正在尝试 return 所有数据,那么您可以使用 foreach,如下所示:

<?php
$str = "Data1 Â Data2 Â  Data 3";
$values = explode("Â", $str);

foreach($values as $index=>$value) {
echo "$index - $value<br>";
}

?>

Returns:

0 - Data1
1 - Data2
2 - Data 3

终于找到了

$values = explode(chr(194), $str);

因为它是用 ANSI 编码的。