http://mee.la/api.php有一个非常简单的API,我想知道是否有人可以帮助我使用它。您可以在http://mee.la/api-about.php了解有关API的更多信息,但只需拨打http://mee.la/api.php?url=http://test.com/,即可返回http://mee.la/2755。我正在尝试创建一个PHP页面,在加载时进行所述调用,并打印响应。任何想法我应该如何开始,因为我只是刚开始学习PHP,
答案 0 :(得分:3)
你可以这样,输入框和表格
<form action="your_script.php" method="POST">
<input type="edit" name="address"/>
<input type="submit" value="go"/>
</form>
并在php中使用curl从api获取url
if (isset($_POST['address'])) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://mee.la/api.php?url=' .
urlencode($_POST['address']));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
}
然后您可以使用标题
打印网址或重定向到该新网址header('Location: ' . $data);
答案 1 :(得分:3)
$myUrl="http://test.com";
$shortUrl=file_get_contents("http://mee.la/api.php?url=".$myUrl);
echo $shortUrl;
答案 2 :(得分:1)
First Way
echo file_get_contents('http://mee.la/api.php?url=http://test.com/');
Second Way
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://mee.la/api.php?url=http://test.com/',
));
$resp = curl_exec($curl);
curl_close($curl);
echo $resp;