您还可以使用 File_get_contents 来获取数据,也可以使用 Javascript 来获取数据,因为有很多选项可用:
<?php
$output = file_get_contents(
'http://www.website.com/');
$output = str_replace('rhs','"rhs"',$output);
$output = str_replace('lhs','"lhs"',$output);
$output = str_replace('error','"error"',$output);
$output = str_replace('icc','"icc"',$output);
$json = json_decode($output);
$rhs = $json->rhs;
?>
并使用 jQuery ajax
jQuery.ajax( url [, settings] )
jQuery.get( url [, data] [, success(data, textStatus, jqXHR)] [, dataType] )
和纯 JavaScript 脚本
function parseURLParams(url) {
var queryStart = url.indexOf("?") + 1;
var queryEnd = url.indexOf("#") + 1 || url.length + 1;
var query = url.slice(queryStart, queryEnd - 1);
if (query === url || query === "") return;
var params = {};
var nvPairs = query.replace(/\+/g, " ").split("&");
for (var i=0; i<nvPairs.length; i++) {
var nv = nvPairs[i].split("=");
var n = decodeURIComponent(nv[0]);
var v = decodeURIComponent(nv[1]);
if ( !(n in params) ) {
params[n] = [];
}
params[n].push(nv.length === 2 ? v : null);
}
return params;
}
使用如下:
var urlString = "http://www.foo.com/bar?a=a+a&b%20b=b&c=1&c=2&d#hash";
var urlParams = parseURLParams(urlString);
它返回一个像这样的对象:
{
"a" : ["a a"], /* param values are always returned as arrays */
"b b": ["b"], /* param names can have special chars as well */
"c" : ["1", "2"] /* an URL param can occur multiple times! */
"d" : [null] /* params without values are set to null */
}
所以
parseURLParams("www.mints.com?name=something")
给
{name: ["something"]}