You should use DOMDocument and DOMXPath or something like that, but if you want it done with regexp, for your given html this should do the trick:
<?php
$html_code="<a href="https://stackoverflow.com/napolnye-pokrytiya/" class="category_cart">
<div class="category_cart__container">
<div style="background-image: url(\"/media/filer_public/b6/49/b6491a4d-5c0d-4a0f-aa9c-b32ea39912c6/category-2.jpg\')" class="category_cart__thumbnail"></div>
<div class="category_cart__content">
<p class="category_cart__title">Напольные покрытия</p>
</div>
</div>
</a>
<a href="http://stackoverflow.com/oboi/" class="category_cart">
<div class="category_cart__container">
<div style="background-image: url(\'/media/filer_public/93/65/9365c3bc-8649-4d9d-932e-144f16ed535c/category-3.jpg\')" class="category_cart__thumbnail"></div>
<div class="category_cart__content">
<p class="category_cart__title">Обои</p>
</div>
</div>
</a>';
//it will look for match between url(' and ')
preg_match_all('/url\(\'(.*?)\'\)/', $html_code, $matches_array);
echo '<pre>';
var_dump($matches_array);
echo '</pre>';
$your_array = array();
//matches including url(' and ') are stored in $matches_array[0], excluded in $matches_array[1] so
foreach($matches_array[1] as $match) {
$your_array[] = $match;
}
echo '<pre>';
var_dump($your_array);
echo '</pre>';
?>
Output:
array(2) {
[0]=>
array(2) {
[0]=>
string(84) "url('/media/filer_public/b6/49/b6491a4d-5c0d-4a0f-aa9c-b32ea39912c6/category-2.jpg')"
[1]=>
string(84) "url('/media/filer_public/93/65/9365c3bc-8649-4d9d-932e-144f16ed535c/category-3.jpg')"
}
[1]=>
array(2) {
[0]=>
string(77) "/media/filer_public/b6/49/b6491a4d-5c0d-4a0f-aa9c-b32ea39912c6/category-2.jpg"
[1]=>
string(77) "/media/filer_public/93/65/9365c3bc-8649-4d9d-932e-144f16ed535c/category-3.jpg"
}
}
array(2) {
[0]=>
string(77) "/media/filer_public/b6/49/b6491a4d-5c0d-4a0f-aa9c-b32ea39912c6/category-2.jpg"
[1]=>
string(77) "/media/filer_public/93/65/9365c3bc-8649-4d9d-932e-144f16ed535c/category-3.jpg"
}
solved How to gather the url text inside HTML-div via regular expression?