1

Ii have the follow structure:

<div class="xGh" style="background-image: url('name_file.jpg');"></div>

I need that output:

name_file.jpg

I try use that answer, but dont work fo me :

$img = $xpath->query(substring-before(substring-after(//div[@class='xGh']/@style, "background-image: url('"), "')"));    

echo $img->item($i)->nodeValue."<br/>";

Look the error:

Test Ideone with error

I have some error in that sintaxe i cant see how is correct...

sry my english

3
  • 1
    substring-before(substring-after(//div[@class='xGh']/@style, "background-image: url('"), "')") works well for me. What is the error message? Commented Nov 1, 2017 at 5:51
  • well : syntax error, unexpected 'echo' (T_ECHO) in C:\xampp\htdocs\bd_all\sp\sp_c.php on line 22 >>> echo $img->item($i)->nodeValue."<br/>" ; Commented Nov 1, 2017 at 5:54
  • @Andersson can u help find that error or made 1 test with code that work fo r you? ideone.com/NoSAAE Commented Nov 1, 2017 at 11:23

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.