简体   繁体   English

如何从url获取内容

[英]How to get contents from url

How can i get contnts from url Text or Json Format如何从 url 文本或 Json 格式获取内容

i am trying to get shortened url created using api link, i am using to methods to get result url, Test and Json.我正在尝试使用 api 链接创建缩短的 url,我正在使用方法来获取结果 url、Test 和 Json。 but Bot are not workig for me.但 Bot 不适合我。 Can someone help in this regards.有人可以在这方面提供帮助。

My Code Using Text Format我的代码使用文本格式

$apilink="https://bitcoinly.in/api?api=API-KEy";
$toshort="https://anysite.com/links/verify";
$links = "$apilink&url=$toshort&format=text";
$lines = file($links);
$link= $lines[0];
echo $link;

Using Json Format使用 Json 格式

$links = "$apilink&url=$toshort&format=json";
$json = file_get_contents($links); 
$data = json_decode($json,true);

$link = $data['shortenedUrl'];
echo $link;

your code seems to be right.. does your server have file_get_contents() on?你的代码似乎是正确的..你的服务器上有 file_get_contents() 吗? if it is on then it will work如果它打开,那么它将起作用

<?php
$api = "YOUR_API_KEY";
$url = "yourdestinationlink.com";
$data = json_decode(file_get_contents("https://bitcoinly.in/api?api=$api&url=$url&format=json"), true); 
//initialize link value in the variable
$link = $data['shortenedUrl'];
echo $link;
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM