用 PHP 用 €-符号分割字符串不起作用?

发布于 2024-09-24 10:02:02 字数 886 浏览 2 评论 0原文

我得到了这个需要解析的蹩脚网站,并且我需要获取包含“”符号内容的html元素。这个页面的实际 html 看起来像这样:

<td>Mais-Lauch-R&ouml;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 &euro;</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 似乎会删除所有包含的标签)

所以 &euro; 被解析为 - 很好。但是当我尝试使用欧元符号分割字符串(实际上比发布的摘录稍长)时,

$data = explode("€", $data);

它不起作用。 explode() 只是不会检测到 € 符号。我尝试按“&euro;”分割,但这也行不通。我还尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

花开浅夏 2024-10-01 10:02:02

字符串中仍然是 - 它只是在浏览器中显示为 €。您需要按 进行拆分。

It's still in the string - it just displays in the browser as €. You'll need to split on instead.

扛刀软妹 2024-10-01 10:02:02

$data =explode("€", $data);

$data = explode("€", $data);

一紙繁鸢 2024-10-01 10:02:02

用简单的 php dom 解析器尝试过...它有效:)

tried it with simple php dom parser... it works :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文