【问题标题】:Anyway to shorten URL via PHP FORM?无论如何要通过 PHP FORM 缩短 URL?
【发布时间】:2013-01-25 00:27:10
【问题描述】:

我目前有人用以下信息填写表格:

  1. 你的名字
  2. 收件人姓名
  3. 留言
  4. 金额

我想知道当他们填写这些信息时我怎么能得到,它将它输入到一个链接中。例如,这是我现在使用的代码:

http://mywebsite.com/picture.php?to=" . $rname . "&from=" . $sname . "&message=" . $message . "&amount=" . $amount .

我现在想知道如何才能使该链接更短?也许使用 TINY URL API 之类的?但是我该怎么做呢?

【问题讨论】:

    标签: php forms tinyurl


    【解决方案1】:

    正如您已经强调的那样,最好的方法是通过 API。如果你安装了 CURL,使用 Tiny URL API 实际上很容易:

    function get_tiny_url($url)  {  
        $ch = curl_init();  
        $timeout = 5;  
        curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);  
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);  
        curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);  
        $data = curl_exec($ch);  
        curl_close($ch);  
    
        return $data;  
    }
    
    //test it out!
    $your_url = 'http://mywebsite.com/picture.php?to=' . $rname . '&from=' . $sname . '&message=' . $message . '&amount=' . $amount;
    $short_url = get_tiny_url($your_url);
    
    //returns your tiny url
    echo $short_url;
    

    Source

    【讨论】:

      猜你喜欢
      • 2013-02-01
      • 1970-01-01
      • 2022-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-04
      • 2010-10-31
      • 2019-09-05
      相关资源
      最近更新 更多