在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;
?>