PHP解析总是有href

发布于 2024-11-16 19:04:25 字数 2594 浏览 0 评论 0原文

我试图在这个 api 中调用我的价格,这不是问题,但问题是价格上有链接而不是常规文本,有人能看到我做错了什么吗?

<?php 
$x = file_get_contents("http://sandbox.api.shopping.com/publisher/3.0/rest/GeneralSearch?apiKey=authorized-key&trackingId=7000610&categoryId=7185&numItems=8&printers");
$xml = simplexml_load_string($x);
foreach($xml->categories->category->items->product as $item)
{
print '<div style="float: left; width: 120px; padding: 10px; overflow: auto; display: block;">';
print '<a rel="nofollow" onclick="javascript:_gaq.push([\'_trackPageview\', \'/outgoing/article_exit_link/789591\']);" href="'.$item->productOffersURL.'"><img src="'.$item->images->image[0]->sourceURL.'" width="100"></a>';
print '<img src="'.$item->rating->ratingImage[0]->sourceURL.'" width="91">';
print "<br/>".l($item->name, $item->productOffersURL, array(), NULL, NULL, TRUE);
//print "<br/>".l($item->shortDescription, $item->productOffersURL, array(), NULL, NULL, TRUE);
// this is where the prices are.
print "<br/>" .l($item->minPrice, $item->productOffersURL, array(), NULL, NULL, TRUE);
print "<br/>".l($item->maxPrice, $item->productOffersURL, array(), NULL, NULL, TRUE);
print '</div>';
}
?>

这是 dom 萤火虫回来了。

<div style="float: left; width: 120px; padding: 10px; overflow: auto; display: block;">

<a href="http://www.shopping.com/Canon-Canon-EOS-400D-Twin-Lens-Kit-Silver-Body-18-55mm-EF-75-300mm-f-4-5-6-Lens/prices~linkin_id-7000610" onclick="javascript:_gaq.push(['_trackPageview', '/outgoing/article_exit_link/789591']);" rel="nofollow"><img width="100" src="http://di1.shopping.com/images/pi/cf/86/d8/58898587-100x100-0-0.jpg?p=p2.48bc03c211719c7871ea&amp;a=2&amp;c=1&amp;l=7000610&amp;t=110620123546&amp;r=1"></a>

<img width="91" src="http://img.shopping.com/sc/pr/sdc_stars_sm_4.5.gif"><br>

<a href="http://www.shopping.com/Canon-Canon-EOS-400D-Twin-Lens-Kit-Silver-Body-18-55mm-EF-75-300mm-f-4-5-6-Lens/prices~linkin_id-7000610">Canon EOS 400D / EOS Rebel XTi Digital Camera with 18-55mm and 75-300mm lenses</a><br>

<a href="http://www.shopping.com/Canon-Canon-EOS-400D-Twin-Lens-Kit-Silver-Body-18-55mm-EF-75-300mm-f-4-5-6-Lens/prices~linkin_id-7000610">598.00</a><br>

<a href="http://www.shopping.com/Canon-Canon-EOS-400D-Twin-Lens-Kit-Silver-Body-18-55mm-EF-75-300mm-f-4-5-6-Lens/prices~linkin_id-7000610">990.00</a>

</div>

Im trying to call my prices in this api which isnt a problem but the problem is the prices have links on them instead of regular text, can anyone see what im doing wrong?

<?php 
$x = file_get_contents("http://sandbox.api.shopping.com/publisher/3.0/rest/GeneralSearch?apiKey=authorized-key&trackingId=7000610&categoryId=7185&numItems=8&printers");
$xml = simplexml_load_string($x);
foreach($xml->categories->category->items->product as $item)
{
print '<div style="float: left; width: 120px; padding: 10px; overflow: auto; display: block;">';
print '<a rel="nofollow" onclick="javascript:_gaq.push([\'_trackPageview\', \'/outgoing/article_exit_link/789591\']);" href="'.$item->productOffersURL.'"><img src="'.$item->images->image[0]->sourceURL.'" width="100"></a>';
print '<img src="'.$item->rating->ratingImage[0]->sourceURL.'" width="91">';
print "<br/>".l($item->name, $item->productOffersURL, array(), NULL, NULL, TRUE);
//print "<br/>".l($item->shortDescription, $item->productOffersURL, array(), NULL, NULL, TRUE);
// this is where the prices are.
print "<br/>" .l($item->minPrice, $item->productOffersURL, array(), NULL, NULL, TRUE);
print "<br/>".l($item->maxPrice, $item->productOffersURL, array(), NULL, NULL, TRUE);
print '</div>';
}
?>

this is the dom firebug is returning.

<div style="float: left; width: 120px; padding: 10px; overflow: auto; display: block;">

<a href="http://www.shopping.com/Canon-Canon-EOS-400D-Twin-Lens-Kit-Silver-Body-18-55mm-EF-75-300mm-f-4-5-6-Lens/prices~linkin_id-7000610" onclick="javascript:_gaq.push(['_trackPageview', '/outgoing/article_exit_link/789591']);" rel="nofollow"><img width="100" src="http://di1.shopping.com/images/pi/cf/86/d8/58898587-100x100-0-0.jpg?p=p2.48bc03c211719c7871ea&a=2&c=1&l=7000610&t=110620123546&r=1"></a>

<img width="91" src="http://img.shopping.com/sc/pr/sdc_stars_sm_4.5.gif"><br>

<a href="http://www.shopping.com/Canon-Canon-EOS-400D-Twin-Lens-Kit-Silver-Body-18-55mm-EF-75-300mm-f-4-5-6-Lens/prices~linkin_id-7000610">Canon EOS 400D / EOS Rebel XTi Digital Camera with 18-55mm and 75-300mm lenses</a><br>

<a href="http://www.shopping.com/Canon-Canon-EOS-400D-Twin-Lens-Kit-Silver-Body-18-55mm-EF-75-300mm-f-4-5-6-Lens/prices~linkin_id-7000610">598.00</a><br>

<a href="http://www.shopping.com/Canon-Canon-EOS-400D-Twin-Lens-Kit-Silver-Body-18-55mm-EF-75-300mm-f-4-5-6-Lens/prices~linkin_id-7000610">990.00</a>

</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一百个冬季 2024-11-23 19:04:25

您的图像标签未关闭。这可能是问题所在。请使用正确的符号

<img /> <!--instead of <img> -->

编辑:

函数 l() 的作用是什么?

print "<br/>".l($item->maxPrice, $item->productOffersURL, array(), NULL, NULL, TRUE);

尝试使用

print "<br/>".$item->maxPrice; 

代替

Your Image-tag is not closed. This could be the problem. Please use a correct notation

<img /> <!--instead of <img> -->

EDIT:

What does function l() do?

print "<br/>".l($item->maxPrice, $item->productOffersURL, array(), NULL, NULL, TRUE);

Try to use

print "<br/>".$item->maxPrice; 

instead

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文