doupiai5597 2016-01-16 06:13
浏览 33

PHP变量不在浏览器中显示

I have the following function:

function getAllProducts($productCount) {
$productsParsed = 0;
$limit = 250;
$pages = ceil($productCount / $limit);
$pageNumber = 1;
$filters = "";
$requestParams = array("page" => $pageNumber, "limit" => $limit, "include" => $filters);

echo $productCount . " products to parse... 
";
echo "=======================================
";

if ($productCount <= $limit) {
    $products = Bigcommerce::getProducts($requestParams);
    $products = (array) $products;

    foreach ($products as $product) {
        $productsParsed++;
        echo $product -> name . "   " . $product -> price . "
";
    }
} else { // More than $limit products in catalog.
    while ($productsParsed <= $productCount) {
        if ($productsParsed === 0 || $productsParsed % $limit > 0) {
            // 0 or not on a multiple of $limit
            $products = Bigcommerce::getProducts($requestParams);
            $productsObject = new ArrayObject($products);
            $productsArray = $productsObject->getArrayCopy();

            foreach ($productsArray as $product) {
                $productsParsed++;
                echo $product -> name . "   " . $product -> price . "
";
            }
        } else {
            // multiple of $limit
            $pageNumber++;
            $requestParams = array("page" => $pageNumber, "limit" => $limit, "include" => $filters);
            $products = Bigcommerce::getProducts($requestParams);
            $productsObject = new ArrayObject($products);
            $productsArray = $productsObject->getArrayCopy();

            foreach ($productsArray as $product) {
                $productsParsed++;
                echo $product -> name . "   " . $product -> price . "
";
            }
        }
    }
}
if ($productsParsed == $productCount) {
    echo "=======================================
 All products accounted for.
";
} else {
    $missingProducts = $productCount - $productsParsed;
    echo "=======================================
" . $missingProducts . " products unaccounted for.
";
}
}

When I run the script at the command line everything performs as expected, I get a correct product count, as well as the output from the $product variable, however in the browser none of the variables echo back, so I end up with:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>

 products to parse... 
=======================================
=======================================
 All products accounted for.

</body>
</html>

What could cause this to echo back differently between the terminal and the browser?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测