【发布时间】:2015-07-25 08:43:56
【问题描述】:
我想从 php 中删除标签以显示此结果:
之前:
1: <span class="n n21" title="Germania"> </span>
2: <a href="/team/34?hl=it-IT" title="FC Schalke 04"><img data-src="http://2015.sofifa.org/15/teams/24/34.png" class="list-mini" src="http://2015.sofifa.org/15/teams/24/34.png"></a>
之后
1: Germania
2: FC Schalke 04
有什么帮助吗?提前谢谢你。
【问题讨论】:
-
1: 和 2: 是行号还是包含在字符串中?我们需要更多信息,你从哪里得到字符串,是静态的吗...
-
你可以试试这个
preg_replace('@(\d+: ).*title="([a-zA-Z0-9 ]+)".*@i', '$1$2', $text)或preg_replace('@(\d+: ).*title="([^"]+)".*@i', '$1$2', $text) -
是的,它们包含在一个字符串中。
-
谢谢@anonymous 的回答,我不知道如何使用 preg_replace 的第一和第二部分 --> '@(\d+: ).*title="([a -zA-Z0-9 ]+)".*@i', '$1$2' -- 我在网上搜索,但我不太明白。
标签: php html tags attributes strip