Code:
$news = array(); foreach ($parse as $index => $value) { preg_match($value, $main_page, $matches); $news[$index] = $matches; } var_dump($news); I get this array:
'name' => array (size=2) 0 => string '<h1 class="moviename-big" itemprop="name">Гладиатор</h1>' (length=65) 1 => string 'Гладиатор' (length=18) 'originalname' => array (size=2) 0 => string '<span itemprop="alternativeHeadline">Gladiator</span>' (length=53) 1 => string 'Gladiator' (length=9) 'year' => array (size=2) 0 => string 'год</td> <td><div style="position: relative"> <a href="/lists/m_act%5Byear%5D/2000/" title="">2000</a>' (length=141) 1 => string '2000' (length=4) 'country_title' => array (size=2) 0 => string 'страна</td> <td><div style="position: relative"> <a href="/lists/m_act%5Bcountry%5D/1/">США</a>, <a href="/lists/m_act%5Bcountry%5D/11/">Великобритания</a> </div></td>' (length=242) 1 => string '<div style="position: relative"> <a href="/lists/m_act%5Bcountry%5D/1/">США</a>, <a href="/lists/m_act%5Bcountry%5D/11/">Великобритания</a> </div>' (length=199) 'slogan' => array (size=2) 0 => string 'слоган</td><td style="color: #555">«Генерал, ставший рабом. Раб, ставший гладиатором. Гладиатор, бросивший вызов империи»</td></tr>' (length=219) 1 => string '«Генерал, ставший рабом. Раб, ставший гладиатором. Гладиатор, бросивший вызов империи»' (length=168) If I write this:
$news = array(); foreach ($parse as $index => $value) { preg_match($value, $main_page, $matches); $news[$index] = $matches[1]; } var_dump($news); Then I get an Undefined offset: 1 . Why and how to fix?
if (isset($matches[1])) { ... }- Gino Pane