0
这是我关于获取div内容的后续问题。第二个功能是一个即时通讯。即时通讯很确定我可以从另一个调用函数,但我不知道如何将它们放入另一个,就像我在这里做的那样。它显然是一个愚蠢的尝试,使代码工作,因为它给了我一个错误:集成函数
黑线弗罗斯特:有货。 :$ 139.99
致命错误:不能重新声明get_string_between()(以前在/home/rambazar/public_html/cron.php:69声明)在/home/rambazar/public_html/cron.php在线69
因为我看到这一点,代码是部分好的,因为它获取产品库存信息和价格标签,但代码停止,我不知道哪里get_string_between重新声明,因为它只被调用。请帮我整理一下,谢谢!
<?php
set_time_limit(1800);
include("admin/include/db.php");
error_reporting(E_ALL);
$res=mysql_query("select * from products");
while($row=mysql_fetch_array($res))
{
$availability=getavailability($row['newegg_productid']);
$price=getprice($row['newegg_productid']);
echo $row['productname']." : ".$availability." : ".$price."<br />";
}
function getavailability($itemId)
{
$url=trim("http://www.newegg.com/Product/Product.aspx?Item=".$itemId);
$ch = curl_init();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$content = curl_exec ($ch);
curl_close ($ch);
$content=strtolower($content);
$buff=$content;
$isAvailable=false;
$pos1=strpos($content,'<p class="note">')+16;
if($pos1==16)return "";
$pos2=strpos($content,'</p>',$pos1);
$availability= trim(substr($content,$pos1,($pos2-$pos1)));
return strip_tags($availability);
}
function getprice($itemId)
{
function get_string_between($string, $start, $end)
{
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0)
return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
$data = file_get_contents("http://www.newegg.com/Product/Product.aspx?Item=".$itemId);
$pricediv = get_string_between($data, '<div class="current" id="singleFinalPrice"><span class="label">Now:', '</div');
$price = strip_tags($pricediv);
return $price;
}
?>
这是代码'cron.php'文件? – 2010-08-29 00:21:30
是的,这是cron文件本身 – crashtest 2010-08-29 12:49:51