[分享]0rz.net短網址的php函數

看板PHP作者 (月季)時間19年前 (2006/06/20 23:14), 編輯推噓17(1702)
留言19則, 13人參與, 最新討論串1/4 (看更多)
因為我自己站上要用...就寫了一個 分享出來給有需要的人用o.o string shorten_url(string) 基本上 就是傳入長網址 傳回短網址 結束o.o <?php function shorten_url($url) { $post_data = array(); $post_data['url'] = $url; $cgi_url = "http://0rz.net/create.php"; $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL, $cgi_url); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); ob_start(); $result = curl_exec($ch); $html = ob_get_contents(); ob_end_clean(); $start = strpos($html, 'input type=hidden name=xxurl value="') + strlen('input type=hidden name=xxurl value="'); $end = strpos($html, '"></form>'); $length = $end - $start; $shortened_url = substr($html, $start, $length); return $shortened_url; } echo shorten_url("http://www.super.long.url.here"); ?> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.162.73.15

06/20 23:32, , 1F
推喔~
06/20 23:32, 1F

06/21 00:00, , 2F
沒得測試,不過針對這種分享精神大推~
06/21 00:00, 2F

06/21 00:24, , 3F
推推推
06/21 00:24, 3F

06/21 01:07, , 4F
您真是好人一枚,雖然目前我還看不懂怎麼用…
06/21 01:07, 4F

06/21 05:33, , 5F
樓上那裡不明白@@?
06/21 05:33, 5F

06/21 11:43, , 6F
讚!~
06/21 11:43, 6F

06/21 14:50, , 7F
要執行因該要開php_curl.dll 吧!~不過我打開APACHE
06/21 14:50, 7F

06/21 14:51, , 8F
不能執行
06/21 14:51, 8F

06/21 16:03, , 9F
有什麼錯誤訊息嗎?我自己兩台機器都可以跑
06/21 16:03, 9F

06/21 21:58, , 10F
不會用+1
06/21 21:58, 10F

06/21 23:32, , 11F
06/21 23:32, 11F

06/21 23:32, , 12F
這行就是用法啦o.o
06/21 23:32, 12F

06/22 06:38, , 13F
空白+1
06/22 06:38, 13F

06/22 09:50, , 14F
網址不能太短 不然他不會讓你縮
06/22 09:50, 14F

06/22 10:33, , 15F
推~
06/22 10:33, 15F

06/22 22:13, , 16F
我也推!分享的精神最高尚
06/22 22:13, 16F

06/23 05:26, , 17F
@@第八行出錯 它說的@@?
06/23 05:26, 17F

06/23 09:42, , 18F
要開curl模組才能用唷
06/23 09:42, 18F

06/30 02:15, , 19F
不會開@@
06/30 02:15, 19F
文章代碼(AID): #14c138UZ (PHP)
文章代碼(AID): #14c138UZ (PHP)