Jump to content

[SOLVED] function output problem blank page...


flusho

Recommended Posts

Hi, I am having trouble recieving output from my function getcf.php, I have tried outputting using the print_r() and count() to check the output but no luck just a blank page here is the code:

<?php
function getcf($catalogFile)
{    
    if (file_exists($catalogFile)) 
  { 
        $data = file($catalogFile); 
        foreach ($data as $line) 
        { 
            $lineArray = explode(':', $line); 
            $sku = trim($lineArray[0]);
            $CATALOG[$sku]['desc'] = trim($lineArray[1]); 
            $CATALOG[$sku]['price'] = trim($lineArray[2]);
          
        } 
    } 
    else 
    { 
        die("Could not find catalog file"); 
  }
}
return $CATALOG;
?>

being called from and returned to print catalog.php here:

<?php
include("/usr431/home/d/r/dr34521/public_html/test/getcf.php");
//invoke function getcf
$cstring = 'catalog.dat';
getcf($cstring);
print_r ($CATALOG);
?>

I just get a blank page, rackin my brains trying figure it out... thanks, Flusho

return should be th last line of your function (before the closing brace)...

<?php
function getcf($catalogFile)
{    
    if (file_exists($catalogFile)) 
  { 
        $data = file($catalogFile); 
        foreach ($data as $line) 
        { 
            $lineArray = explode(':', $line); 
            $sku = trim($lineArray[0]);
            $CATALOG[$sku]['desc'] = trim($lineArray[1]); 
            $CATALOG[$sku]['price'] = trim($lineArray[2]);
          
        } 
    } 
    else 
    { 
        die("Could not find catalog file"); 
  }
return $CATALOG;
}
?>

 

then call it like this...

<?php
include("/usr431/home/d/r/dr34521/public_html/test/getcf.php");
//invoke function getcf
$cstring = 'catalog.dat';
$catalog = getcf($cstring);
print_r ($catalog);
?>

 

try to reserve UPPCASE var for constants.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.