Изменить $js=file_get_contents на $string=file_get_contents

223
13 апреля 2017, 19:46

Есть код, получает заголовок и ссылку со стороннего сайта.

<?php
protected function getcates($nom){
$part = "snippet";
$js=file_get_contents("сайт.ру");
if(preg_match('#push\((?<json>.*?)\);#',$js,$match))
{
$wares=json_decode($match['json'])->wares;
$html = '';
foreach ($wares as $item)
{
$itemtitle = $item->title;
$arr1 = array('XXX');
$arr2 = array('');
$itemtitle=str_replace($arr1, $arr2, $item->title);
$item->title=str_replace($arr1, $arr2, $item->title);
$itemtitle = preg_replace('/[^\p{L}0-9 \!]/iu', ' ', $itemtitle);
$block = "";
$this->url = "https://www.googleapis.com/youtube/v3/search?key={$this->config["key"]}&part=$part&order={$this->config[$nom.'sortingresults']}&maxResults={$this->config[$nom.'number']}&q=".urlencode($itemtitle)."&videoEmbeddable=true&videoSyndicated=true&type=video";
$data = $this->http(TRUE);
//var_dump($data);
foreach ($data->items as $yt) {
$block .= "
сюда поместить то, что в echo выводится так"<a href=\"".$match[1][$i]."\">".$match[2][$i]."</a><br/>";
только без echo
";
}
if(!empty($block)){
$html .= 'верхнее оформление'.$block.'нижнее оформление';
}
}
}
return $html;
}
?>

Помогите в него внедрить этот код:

<?
$string=file_get_contents("https://e-pay.tv/adverts/iframe.php?aff=101005&color=0a97fc&blocks=10&width=400&type=vertical");
preg_match_all("/<a.*?href=\"(.*?)\">.*?<h2.*?>(.*?)<\/h2>/s", $string, $match);
$n = count($match[1]);
for ($i = 0; $i < $n; $i++) 
echo "<a href=\"".$match[1][$i]."\">".$match[2][$i]."</a><br/>";
?> 

Нужно, чтобы в первом коде получали данные не через $js=file_get_contents; а через $string=file_get_contents; и далее по коду.

Спасибо!

READ ALSO
read(sock&hellip;) и write(sock&hellip;) не работают синхронно

read(sock…) и write(sock…) не работают синхронно

C++, Ununtu 1604 LTS, Компилятор g++

211
Сравнение множества значений

Сравнение множества значений

Как коротко сравнить много значений на равенство? Надо такое поведение:

238
Двойная итерация в одном цикле

Двойная итерация в одном цикле

Как сделать так, чтобы одновременно в одном цикле шли две итерации (например i и j)?

242
Ошибка Broken file, keyframe not correctly marked

Ошибка Broken file, keyframe not correctly marked

При открытии файлаogv выдает в дампе ошибку "[ogg @ 00f0c400] Broken file, keyframe not correctly marked

258