所以这是我从 SEOMOZ API 中提取的示例代码,用于目标 URL 上的链接。这个脚本是命令行
#!/usr/bin/php
<?php
$objectURL = $domain_url;$accessID = "xyz";
$secretKey = "xya";
$expires = mktime() + 300;
$stringToSign = $accessID."\n".$expires;
$binarySignature = hash_hmac('sha1', $stringToSign, $secretKey, true);
$urlSafeSignature = urlencode(base64_encode($binarySignature));
$urlToFetch = "http://lsapi.seomoz.com/linkscape/links/".urlencode($objectURL)."?AccessID=".$accessID."&Expires=".$expires."&Signature=".$urlSafeSignature."&SourceCols=26&&TargetCols=4&Scope=page_to_domain&Filter=follow&Sort=page_authority&Limit=10";
$handle = fopen($urlToFetch, "r");
$links_contents = '';
while (!feof($handle)) {
$links_contents .= fread($handle, 8192);
}
fclose($handle);
echo $links_contents;
?>
该脚本的结果是它以 JSON 格式返回信息,但不是以有序的方式返回大量信息。将结果格式化为更整洁/可读的显示的最简单方法是什么?
这是来自 JSON 的返回
{
"frid": 1,
"lf": 2,
"lrid": 3,
"lsrc": 4,
"ltgt": 5,
"luuu": 6,
"prid": 7,
"ufq": 8,
"upl": 9,
"urid": 10
}