mardi 4 juillet 2017

PHP parser on WordPress website? How to display information?

I made a PHP parser that copies certain information from the site. How do I display this information on my WordPress website? I mean that the information was displayed in the records of WordPress.

Code parser:

    <?php
header('Content-type: text/html; charset=utf-8');
require 'phpQuery.php';

function parseArticle($url){
    $file = file_get_contents($url);
    $doc = phpQuery::newDocument($file);
    $text = $doc->find('.post-head')->html();
    print_arr($text);
    $text = $doc->find('.post-body')->html();
    print_arr($text);
}


function print_arr($arr){
    echo '<pre>' . print_r($arr, true) . '</pre>';
}

$url = 'http://ift.tt/2tHrzov';
$file = file_get_contents($url);

$doc = phpQuery::newDocument($file);

foreach($doc->find('.blog-posts .post-outer .post') as $article){
    $article = pq($article);
    $text = $article->find('.entry-title a')->html();
    print_arr($text);
    $texturl = $article->find('.entry-title a')->attr('href');
    parseArticle($texturl);
    $text = $article->find('.date-header')->html();
    print_arr($text);
    $img = $article->find('.thumb a')->attr('style');
    $img."<br>"; if (preg_match('!background:url.(.+). no!',$img,$match)) { 
$imgurl = $match[1]; 
} else 
{echo "<img src = http://ift.tt/2tHrzov".$item.">";}  

    echo "<img src='$imgurl'>";
}
?>




Aucun commentaire:

Enregistrer un commentaire