Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Function 积分函数_Function_Integrate - Fatal编程技术网

Function 积分函数

Function 积分函数,function,integrate,Function,Integrate,这是我关于获取div内容的问题的后续内容。第二个功能是我很难使用的功能。我很确定我可以从另一个函数调用一个函数,但我不确定是否可以像我在这里做的那样将它们放到另一个函数中。显然,试图让代码正常工作是愚蠢的,因为它给了我一个错误: Blackline Frostbyte:库存中:$139.99 致命错误:无法在第69行的/home/rambazar/public_html/cron.php:69中重新声明get_string_between()(以前在/home/rambazar/public_h

这是我关于获取div内容的问题的后续内容。第二个功能是我很难使用的功能。我很确定我可以从另一个函数调用一个函数,但我不确定是否可以像我在这里做的那样将它们放到另一个函数中。显然,试图让代码正常工作是愚蠢的,因为它给了我一个错误:

Blackline Frostbyte:库存中:$139.99

致命错误:无法在第69行的/home/rambazar/public_html/cron.php:69中重新声明get_string_between()(以前在/home/rambazar/public_html/cron.php中声明)

正如我看到的,代码部分是正确的,因为它获得了产品库存信息和价格标签,但是代码停止了,我不知道在哪里重新声明了get\u string\u 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;
}
?>

getprice()
函数中取出
get\u string\u between()
,您就可以开始了:

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);
}

function getprice($itemId)
{
    $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;
}
函数get\u string\u-between($string,$start,$end) { $string=”“.$string; $ini=strpos($string,$start); 如果($ini==0) 返回“”; $ini+=strlen($start); $len=strpos($string,$end,$ini)-$ini; 返回substr($string,$ini,$len); } 函数getprice($itemId) { $data=文件\u获取\u内容(“http://www.newegg.com/Product/Product.aspx?Item=“$itemId);
$pricediv=get_string_between($data,'Now:','这段代码是
cron.php
文件吗?是的,这是cron文件本身