код
<?php
define('_IN_JOHNCMS', 1);
require '../incfiles/core.php';
require 'functions.php';
header("Content-type:text/html; charset=utf-8");
$type = isset($_REQUEST['type']) ? trim($_REQUEST['type']) : false;
switch ($act)
{
default:
$textl = 'Новости футбола';
$headmod = 'fnews';
require '../incfiles/head.php';
echo '<div class="orange_bg"><b>Новости футбола</b></div>';
require_once 'phpQuery.php';
$content = file_get_contents('http://sport.ua/news/archive?sport=1');
$document = phpQuery::newDocument($content);
$list_elements = $document->find('.hentry');
foreach ($list_elements as $element)
{
$pq = pq($element);
$title_news = $pq->find('.hentry__title')->text();
$data_news = $pq->find('.hentry__published')->text();
if (strpos($title_news, 'Смотреть Видео') > -1) {}else{
$link = $pq->find('a')->attr('href');
$link = str_replace('//sport.ua/news/', '', $link);
echo '<div class="c">';
$img_news = $pq->find('img ')->attr('src');
$img_news = str_replace('//', 'http://', $img_news);
if (!$img_news)
$img_news = 'nophoto.png';
echo '<table><tr><td><a href="index.php?act=news&id=' . $link . '"><img style="float:left;margin-right:10px;max-width:150px;" src="' . $img_news . '" /></a></td>';
echo '<td><a href="index.php?act=news&id=' . $link . '">' . $title_news . '</a><br/><small>' . $data_news . '</small></td></tr></table>';
echo '<div style="clear:both;"></div></div>';
}
}
break;
case 'news':
$textl = 'Новости футбола';
$headmod = 'fnews';
require '../incfiles/head.php';
require_once 'phpQuery.php';
$content = file_get_contents('http://sport.ua/news/' . $id . '');
$document = phpQuery::newDocument($content);
$list_elements = $document->find('#news-page');
$pq = pq($list_elements);
$title_news = $pq->find('.news-title>h1')->text();
$title_news_sub = $pq->find('.news-title>h2')->text();
echo '<div class="orange_bg"><b>' . $title_news . '</b></div>';
if ($title_news_sub) echo '<div class="info">' . $title_news_sub . '</div>';
echo '<div class="list1">';
$img_news = $pq->find('img ')->attr('src');
$img_news = str_replace('//', 'http://', $img_news);
echo '<center><img style="width:100%;max-width:450px;" src="' . $img_news . '" /></center>';
echo '<div class="info">';
$pq->find('script, figure')->remove();
$text_news = $pq->find('.content')->text();
$text_news = preg_replace('#<script>(.*)</script>#isU', '', $text_news);
$text_news = preg_replace('#<figure>(.*)</figure>#isU', '', $text_news);
$text_news = preg_replace('#Источни(.*)Если#isU', '', $text_news);
$text_news = str_replace('
', '<br/>', $text_news);
$text_news = str_replace('вы нашли ошибку, пожалуйста, выделите фрагмент текста и нажмите Ctrl+Enter.', '', $text_news);
$text_news = str_replace('Подписывайся на наш канал в Telegram и узнавай все самые свежие новости первым!', '', $text_news);
$text_news= preg_replace("/s{2,}/"," ",$text_news);
//$text_news = preg_replace('/\n{2,}/',"",$text_news);
//$text_news = preg_replace('<br/>',"",$text_news);
print_r(rtrim(ltrim($text_news)));
//echo '' . trim(nl2br($text_news)) . '';
echo '<div style="clear:both;"></div></div>';
echo '<div class="menu"><a href="index.php"><input type="submit" name="submit" value="Новости футбола" /></a></div>';
break;
}
require '../incfiles/end.php';
не виводит картинки и текст