Is it possible to modify walkable from the old Dr site in parsing?

$subject = file_get_contents('http://yandex.ru/');
 $pattern = '|<span\sclass="news__item-inner">(.*)</span>|isU';
$pars = preg_match_all($pattern, $subject, $out);
print_r($out);

This was the view which I have displayed on the website:5dfbbae0d78e8498676845.png
Question: -can I remove the array?
-to make the picture smaller and to the left?
-to have issued 1 news randomly and not the whole list. (well I understand it is possible to choose only 1 tag news, but I will always show 1 news =( hotelosby to change the news to another in the interval of 1 minute.
April 3rd 20 at 18:45
2 answers
April 3rd 20 at 18:47
Solution
Yes. All you can do.
April 3rd 20 at 18:49
Solution
All items: can.

UPD: new year event.
<?php
function getNews () {
 static $news = [];

 if (empty($news)) {
 $subject = file_get_contents('http://yandex.ru/');
 $pattern = '|<span\sclass="news__item-inner">(.*)</span>|isU';
 $pars = preg_match_all($pattern, $subject, $news);
 $news = empty($news) ? [] : $news[0];
}

 return $news;
}

getRandomNew function () {
 $news = getNews();
 return $news[array_rand($news)];
}
?>

<div class="news>
 <div class="news__random>
 <?= getRandomNew() ?>
</div>

 <ul class="news__list">
 <?php foreach (getNews() as $new): ?>
the <li>
 <?= $new ?>
</li>
 <?php endforeach; ?>
</ul>
</div>
Nuea @arvilla.Armstro - Frederiqu commented on April 3rd 20 at 18:52
Reproduce code on the website threw an error in the syntax
return $news[array_rand($news)];
Corrected, and then does not display anything =) just empty without any errors, added the words in the div is displayed, but no news =( - arvilla.Armstro commented on April 3rd 20 at 18:55
@arvilla.Armstro, do var_dump($news) - Frederiqu commented on April 3rd 20 at 18:58
@Frederiqu, writes NULL - arvilla.Armstro commented on April 3rd 20 at 19:01
@arvilla.Armstro, the problem in parsing, I don't know why you have worked. You need to fix it. The original code does not work, an empty array is obtained. - Frederiqu commented on April 3rd 20 at 19:04
@Frederiqu, but how so I connect my lists I'm even a picture made I just need to place them correctly so I ask how. - arvilla.Armstro commented on April 3rd 20 at 19:07
Wrong code bit you gave Sori. See space must be in the class after the class name:
$subject = file_get_contents('http://yandex.ru/');
 $pattern = '|<span\sclass="news__item-inner ">(.*)</span>|isU';
$pars = preg_match_all($pattern, $subject, $out);
print_r($out);

I used the space bar this not put me Nitsche not ship and when, after the class name space then lists news: sclass="news__item-inner "
the space put in your code it's all gone here's a photo:
5dfc1661c4edc882504658.png
The only thing that I can not understand your code randomly makes the news, and then for some reason randomly and is given below in spots for a full list of news I thought they will not. - arvilla.Armstro commented on April 3rd 20 at 19:10
@Frederiqu, thank you, helped me) - arvilla.Armstro commented on April 3rd 20 at 19:13

Find more questions by tags PHP