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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.