1

我正在尝试将此脚本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']));

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

4

1 回答 1

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;
于 2012-12-09T14:02:52.850 回答