用 PHP 用 €-符号分割字符串不起作用?
我得到了这个需要解析的蹩脚网站,并且我需要获取包含“€
”符号内容的html元素。这个页面的实际 html 看起来像这样:
<td>Mais-Lauch-Rösti <font color=#000000 size=1>(1,2,9,11)</font> mit Paprikasauce <font color=#000000 size=1>(3,9)</font><nobr><b> 2,10 €</b></nobr><br/>........
所以我使用 DOM 来获取元素的内容。不幸的是,这最终像下面的代码一样(通过 var_dump()):(
string(270) "Mais-Lauch-Rösti (1,2,9,11) mit Paprikasauce (3,9) 2,10 €.........
在使用像 $td->item(0)->nodeValue;
这样的东西时,dom 似乎会删除所有包含的标签)
所以 €
被解析为 €
- 很好。但是当我尝试使用欧元符号分割字符串(实际上比发布的摘录稍长)时,
$data = explode("€", $data);
它不起作用。 explode() 只是不会检测到 € 符号。我尝试按“€”分割,但这也行不通。我还尝试使用 str_replace() 和 preg_replace() - 但它们都无法识别该符号:(
我错过了什么吗?我做错了什么?
i got this crappy website i need to parse and the html-element i need to get the contents of contains "€
" symbols. the actual html of this page looks like this:
<td>Mais-Lauch-Rösti <font color=#000000 size=1>(1,2,9,11)</font> mit Paprikasauce <font color=#000000 size=1>(3,9)</font><nobr><b> 2,10 €</b></nobr><br/>........
so i use DOM to get the contents of the element. unfortunately, this ends up like the following code (via var_dump()):
string(270) "Mais-Lauch-Rösti (1,2,9,11) mit Paprikasauce (3,9) 2,10 €.........
(dom seems to strip all containing tags when using sth like $td->item(0)->nodeValue;
)
so the €
was parsed to €
- fine. but when i try to split the string (that is actually a little longer than the posted excerpt) by the €-symbol by using
$data = explode("€", $data);
it won't work. explode() just won't detect the € symbol. i tried splitting by "€", but this won't work either. i also tried using str_replace() and preg_replace() - but none of them would recognize the symbol :(
am i missing something? what am i doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
字符串中仍然是
€
- 它只是在浏览器中显示为 €。您需要按€
进行拆分。It's still
€
in the string - it just displays in the browser as €. You'll need to split on€
instead.$data =explode("€", $data);
$data = explode("€", $data);
用简单的 php dom 解析器尝试过...它有效:)
tried it with simple php dom parser... it works :)