如何使用PHP API [英] How to use a PHP API

查看:72
本文介绍了如何使用PHP API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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,

There is a really simple API at http://mee.la/api.php, and I was wondering if anyone could help me use it. You can read more about the API at http://mee.la/api-about.php but all it is is a call to http://mee.la/api.php?url=http://test.com/, which returns http://mee.la/2755. I am trying to create a PHP page which when loaded makes said call, and prints the response. Any ideas how I should start because I'm only just starting to learn PHP,

推荐答案

您可以执行以下操作,放入输入框和表格

You can do something like this, put input box and a form

<form action="your_script.php" method="POST">
   <input type="edit" name="address"/>
   <input type="submit" value="go"/>
</form>

在PHP中,使用curl从API获取URL

and in PHP use curl to get the URL from the API

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);
}

然后您可以打印URL,创建html链接或使用标头重定向到该新URL

then you can print the URL, create html link or redirect to that new URL using header

header('Location: ' . $data);

这篇关于如何使用PHP API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆