flusho Posted May 7, 2007 Share Posted May 7, 2007 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 Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted May 7, 2007 Share Posted May 7, 2007 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. Quote Link to comment Share on other sites More sharing options...
flusho Posted May 7, 2007 Author Share Posted May 7, 2007 Thanks Toon, that was killin me. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.