Answer the question
In order to leave comments, you need to log in
How to get the path to the image?
<div class="zoomContainer" style="-webkit-transform: translateZ(0);position:absolute;left:773.5px;top:288px;height:414px;width:622px;">
<div class="zoomLens" style="background-position: 0px 0px;width: 242.96875px;height: 242.81524926686217px;float: right;display: none;overflow: hidden;z-index: 999;-webkit-transform: translateZ(0);opacity:0.4;filter: alpha(opacity = 40); zoom:1;width:242.96875px;height:242.81524926686217px;background-color:white;cursor:default;border: 1px solid #000;background-repeat: no-repeat;position: absolute;"/>
<div class="zoomWindowContainer" style="width: 400px;">
<div class="zoomWindow" style="overflow: hidden; background-position: 0px 0px; text-align: center; background-color: rgb(255, 255, 255); width: 400px; height: 400px; float: left; background-size: 1024px 682px; display: none; z-index: 100; border: 4px solid rgb(136, 136, 136); background-repeat: no-repeat; position: absolute; background-image: url("/files/images/g_102_734659.jpg");"/>
</div>
</div>
Answer the question
In order to leave comments, you need to log in
I would suggest using substring-before and substring-after. But first, pay attention to the quotes in the background-image, in the form that this will not work for you. Here is my simplified working version:
$html = '<div class="zoomContainer">
<div class="zoomWindow" style="position: absolute; background-image: url(\'/files/images/g_102_734659.jpg\');"/>
</div>';
$doc = new DOMDocument('UTF-8');
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$res = $xpath->evaluate('substring-before(substring-after(//div[@class="zoomWindow"]/@style, "background-image: url(\'"), "\')")'); //важно использовать именно evaluate
var_dump($res); // $res - итоговая строка
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question