另一款百度短網址生成 PHP 程式碼

4,063 0

今天早上我發表了一篇利用百度短網址 API 生成短網址的教學和程式碼,然後在 CSDN 發現了另一個更好的生成百度短網址方案,於是就想轉發過來分享給小夥伴們,也可以和我上一篇文章的版本進行一下比較,反正我是覺得它的比較快速方便,設計邏輯也很精密,下面是程式碼部分。

PHP 程式碼

PHP
<?php
function send_post($url, $post_data) {
    $postdata = http_build_query($post_data);
    $options = array(
        'http' => array(
            'method' => 'POST',
            'header' => 'Content-type:application/x-www-form-urlencoded',
            'content' => $postdata,
            'timeout' => 15 * 60
        )  
    );  
    $context = stream_context_create($options);  
    $result = file_get_contents($url, false, $context);  
    return $result;  
}
$post_data = array(
    'url' => 'URL'
);
$json_data =  send_post('http://dwz.cn/create.php', $post_data);
$arr = json_decode($json_data,true);
echo $arr['tinyurl'];
?>

評論

(0)

暫無評論,來說兩句吧

發佈評論

© 2026 一紙忘憂. 保留所有權利.

一紙忘憂的個人網站,關於技術探索與日常生活,記錄 Web 開發、後端與 DevOps 實踐,分享軟體工具、數位體驗,以及程式碼之外的見聞與思考。