Ax_人工智能管理局&非正常人类研究中心

ChatGPT帮我写的PHP代码

2023-04-06 阿星 非正常人类研究中心 https://www.admxn.com/blog/laboratory/184.html
<style>
    ul {
        list-style: none;
        margin: 0;
        padding: 0;
    }
    li {
        margin-bottom: 30px;
        padding: 20px;
        border: 1px solid #ccc;
        border-radius: 5px;
    }
    .title {
        font-size: 24px;
        font-weight: bold;
        margin-bottom: 10px;
    }
    .excerpt {
        margin-bottom: 10px;
        color: #666;
    }
    .thumbnail {
        margin-top: 10px;
        text-align: center;
    }
    .thumbnail img {
        max-width: 100%;
        max-height: 200px;
    }
</style>
<?php
$url = "https://www.zhihu.com/billboard";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);

preg_match_all('/<a class="HotList-item"(.+?)<\/a>/', $output, $matches);

if(count($matches[0]) > 0) {
    echo "<ul>";
    for($i = 0; $i < 10; $i++) {
        if(isset($matches[0][$i])) {
            preg_match('/<div class="HotList-itemIndex HotList-itemIndexHot">(.+?)<\/div>/', $matches[0][$i], $num_match);
            preg_match('/<div class="HotList-itemTitle">(.+?)<\/div>/', $matches[0][$i], $title_match);
            preg_match('/<div class="HotList-itemExcerpt">(.+?)<\/div>/', $matches[0][$i], $excerpt_match);
            preg_match('/<img src="(.+?)" alt="/', $matches[0][$i], $img_match);
            $num = isset($num_match[1]) ? $num_match[1] : '';
            $title = isset($title_match[1]) ? $title_match[1] : '';
            $excerpt = isset($excerpt_match[1]) ? $excerpt_match[1] : '';
            $img = isset($img_match[1]) ? $img_match[1] : '';
            echo "<li>";
            echo "<div class='title'>序号: ".$num."</div>";
            echo "<div class='title'>标题: ".$title."</div>";
            echo "<div class='excerpt'>简介: ".$excerpt."</div>";
            if(!empty($img)) {
                echo "<div class='thumbnail'><img src='".$img."'></div>";
            }
            echo "</li>";
        }
    }
    echo "</ul>";
} else {
    echo "没有匹配到任何内容!";
}
?>
ChatGPT

添加新评论