URL缩短代码以实际缩短页面

时间:2012-12-09 13:59:20

标签: php url

我正试图在我自己的网站上使用这个脚本https://github.com/briancray/PHP-URL-Shortener。在自述文件中,它告诉了这一点

要使用PHP以编程方式缩短URL,请使用以下代码:

$shortenedurl = file_get_contents('http://yourdomain.com/shorten.php?longurl=' . urlencode('http://' . $_SERVER['HTTP_HOST']  . '/' . $_SERVER['REQUEST_URI']));

如果我将此代码添加到我网站的任何页面,它应该缩短实际的网站链接。但它不会向我显示链接并缩短它。

1 个答案:

答案 0 :(得分:1)

否则

$shortenedurl = file_get_contents('http://yourdomain.com/shorten.php?longurl=' . urlencode('http://' . $_SERVER['HTTP_HOST']  . '/' . $_SERVER['REQUEST_URI']));

只会缩短它并将其保存为变量。要显示它,您需要使用echo显示变量的内容。试试这个:

$shortenedurl = file_get_contents('http://yourdomain.com/shorten.php?longurl=' . urlencode('http://' . $_SERVER['HTTP_HOST']  . '/' . $_SERVER['REQUEST_URI']));
echo $shortenedurl;
相关问题