gpt4 book ai didi

php - 使用 XPATH(和 PHP)从样式属性中选择背景 url

转载 作者:搜寻专家 更新时间:2023-10-31 21:43:36 25 4
gpt4 key购买 nike

我只想从这个背景图像样式属性中选择 url,这可以用 XPATH 实现吗?

 <a href="http://www.test.com" style="background-image: url('http://www.test.com/hello.jpg');">test</a>

我有类似的东西

$url  = $xpath->query('//a//@style');

最佳答案

使用:

substring-before(substring-after(@style, "'"),
"'"
)

基于 XSLT 的验证:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/*">
"<xsl:value-of select=
"substring-before(substring-after(@style, &quot;&apos;&quot;),
&quot;&apos;&quot;
)
"/>"
</xsl:template>

</xsl:stylesheet>

当此转换应用于提供的 XML 文档时:

 <a href="http://www.test.com" style=
"background-image: url('http://www.test.com/hello.jpg');">test</a>

产生了想要的、正确的结果:

 "http://www.test.com/hello.jpg"

关于php - 使用 XPATH(和 PHP)从样式属性中选择背景 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7333278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com