Extract value from background-image style attribute with xpath

前端 未结 1 340
广开言路
广开言路 2021-01-27 03:05

Ii have the follow structure:

I need that output:

相关标签:
1条回答
  • 2021-01-27 03:39

    1) You lost quotes wrapping xpath - it's string.

    2) with dom xpath, query returns set of nodes while to receive string result it's better to use evaluate

    $img = $xpath->evaluate('substring-before(substring-after(//div[@class=\'xGh\']/@style, "background-image: url(\'"), "\')")');    
    
    echo $img; // it contains name_file.jpg
    

    demo

    0 讨论(0)
提交回复
热议问题