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

查看:22
本文介绍了如何使用 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天全站免登陆