0
我有从我的数据库中提取信息然后使用API检查它的代码。我试图将返回信息自定义到表中。我会添加一张照片来显示我想要的内容。我到处搜索,我不知道如何编码。不要担心CSS只是获取信息来填充表格。以XML格式返回的样式Feed内容
<?php
$key = "********************";
$address = urlencode($CustomFields->field('jr_address',$listing,false,false));
$city = $listing['Category']['title'];
$zip = $CustomFields->field('jr_zipcode',$listing,false,false);
$url = "http://api.greatschools.org/schools/nearby?key={$key}&address={$address}&city={$city}&state=MI&zip={$zip}&schoolType=public-charter&levelCode=elementary-schools&minimumSchools=50&radius=10&limit=5";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
curl_close($curl);
print_r($response);
?><style type='text/css'>gsId{display:none;}name{color:#9BB055; font-size:18px;}type{display:none;}gradeRange{}enrollment{}gsRating{}city{display:none;}state{display:none;}district{}districtNCESId{display:none;}address{display:none;}phone{display:none; }fax{display:none;}ncesId{display:none;}lat{display:none;}lon{display:none;}</style>
返回代码:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<schools>
<school>
<gsId>6350</gsId>
<name>Chinese Education Center</name>
<type>public</type>
<gradeRange>K-5</gradeRange>
<enrollment>63</enrollment>
<gsRating>3</gsRating>
<city>San Francisco</city>
<state>CA</state>
<district>San Francisco Unified School District</district>
<districtNCESId>0634410</districtNCESId>
<address>657 Merchant St., San Francisco, CA 94111</address>
<phone>(415) 291-7918</phone>
<fax>(415) 291-7965</fax>
<ncesId>063441005596</ncesId>
<lat>37.795</lat>
<lon>-122.4042</lon>
<overviewLink>http://www.greatschools.org/california/san-francisco/6350-Chinese-Education-Center/?s_cid=gsapi</overviewLink>
<ratingsLink>http://www.greatschools.org/school/rating.page?state=CA&id=6350&s_cid=gsapi</ratingsLink>
<reviewsLink>http://www.greatschools.org/school/parentReviews.page?state=CA&id=6350&s_cid=gsapi</reviewsLink>
</school>
<school>
<gsId>6389</gsId>
<name>Gordon J. Lau Elementary School</name>
<type>public</type>
<gradeRange>K-5</gradeRange>
<enrollment>667</enrollment>
<gsRating>7</gsRating>
<city>San Francisco</city>
<state>CA</state>
<district>San Francisco Unified School District</district>
<districtNCESId>0634410</districtNCESId>
<address>950 Clay St., San Francisco, CA 94108</address>
<phone>(415) 291-7921</phone>
<fax>(415) 291-7952</fax>
<website>http://www.gjles.org/</website>
<ncesId>063441005599</ncesId>
<lat>37.794</lat>
<lon>-122.4086</lon>
<overviewLink>http://www.greatschools.org/california/san-francisco/6389-Gordon-J.-Lau-Elementary-School/?s_cid=gsapi</overviewLink>
<ratingsLink>http://www.greatschools.org/school/rating.page?state=CA&id=6389&s_cid=gsapi</ratingsLink>
<reviewsLink>http://www.greatschools.org/school/parentReviews.page?state=CA&id=6389&s_cid=gsapi</reviewsLink>
</school>
</schools>
我不知道该怎么写脚本,使它看起来像这样: 链接到图片: link text
所以新文件看起来像这样?
<?php
$key = "xxxxxxxxxxxxxxxxxxxxxxxx";
$address = urlencode($CustomFields->field('jr_address',$listing,false,false));
$city = $listing['Category']['title'];
$zip = $CustomFields->field('jr_zipcode',$listing,false,false);
$url = "http://api.greatschools.org/schools/nearby?key={$key}&address={$address}&city={$city}&state=MI&zip={$zip}&schoolType=public-charter&levelCode=elementary-schools&minimumSchools=50&radius=10&limit=5";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
curl_close($curl);
echo (xml2html($response, "/xslt/schools.xsl");
?>
我得到回音线的错误。
这是哪里去的?
<?php
function xml2html($xmldata, $xslPath)
{
/* $xmldata -> your XML */
/* $xsl -> XSLT file */
$arguments = array('/_xml' => $xmldata);
$xsltproc = xslt_create();
xslt_set_encoding($xsltproc, 'ISO-8859-1');
$html =
xslt_process($xsltproc, 'arg:/_xml', $xslPath, NULL, $arguments);
if (empty($html)) {
die('XSLT processing error: '. xslt_error($xsltproc));
}
xslt_free($xsltproc);
return $html;
}
?>
也许有不止一个学校一个XML文档将更有帮助。另外,每所学校都有经纬度,但是应该计算与学校距离的点的坐标是什么?这不是在你的问题中指定的。 – 2011-01-23 06:58:04
我在上面的代码中包含了另一所学校。就纬度和经度而言,我不知道你是否看过我发布的图像(在原始文章的底部)。我只会隐藏它。当我将地址信息发送给API时,它将排序哪些学校更接近。我的挑战是我的知识是非常有限的,我迷失于如何编码任何这些。 – 2011-01-23 16:56:52