Jump to content

Please check the line of my function


gudfry

Recommended Posts

hi all;

 

        I have a recursive function the read the file, but its doesn work properly so It a big problem for me as a newbie in php, i need help to someone, here is my function that read the file and returning the line of file as array of string.

 

function processFile($filename) {

       $lines = file($filename);
       $returnArray= array();
       		foreach ($lines as $line) {
         	$output=processFile($string);
            if (gettype($output)=="array") {
               $returnArray[]='<tr><td>Title:</td><td>'.($output[0]).'</td><td>Value:</td><td>'.$output[1].'</td></tr>';
            }      
         }
         return $returnArray;
      }

I have another page to test the my function if it running but this is the way i got the error.

Warning: file() expects parameter 1 to be string, array given in F:\

Warning: Invalid argument supplied for foreach() in F

 

require_once('chadlib.php');
      $string = file('test.php');
	$strings=processFile($string);
         echo '<table>';
            foreach ($strings as $element => $value) {
         echo $value;
         echo '</table>';
	 }

 

please check theline of my code. thank in advance.

Link to comment
https://forums.phpfreaks.com/topic/116370-please-check-the-line-of-my-function/
Share on other sites

try change it to this...

function processFile($filename) {

       $lines = file($filename);
       $returnArray= array();
       		foreach ($lines as $line) {
         	$output=processFile($string);
            if (gettype($output)=="array") {
               $return = '<tr><td>Title:</td><td>'.($output[0]).'</td><td>Value:</td><td>'.$output[1].'</td></tr>';
            }      
         }
         return $return;
      }

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.