4

php文件中将调试结果输出到console控制台

 2 years ago
source link: https://chegva.com/4712.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

php文件中将调试结果输出到console控制台

在php文件中调用echo将curl获取结果输出到console控制台。

<?php
function getArticle()
{
    $url="https://interface.meiriyiwe.com/article/random";
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_NOSIGNAL, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
    $file_contents = curl_exec($ch);
    curl_close($ch);


    //echo "<script>console.log(".$file_contents.")</script>";
    $info=json_decode($file_contents);
    $out['title'] = $info->data->title;
    $out['author'] = $info->data->author;
    $out['content'] = $info->data->content;
    return $out;
}
    $arr = getArticle();
    //echo "<script>console.log(".print_r($arr).")</script>";
    $output .= '<div id="article_show"><h1>'. $arr['title'] . '</h1><p class="article_author"><span>'. $arr['author'] .'</span></p><div class="article_text">'. $arr['content'] .'</div></div>';
    echo $output;
?>
anzhihe安志合个人博客,版权所有丨 如未注明,均为原创 丨转载请注明转自:https://chegva.com/4712.html | ☆★★每天进步一点点,加油!★★☆

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK