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.

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.

Didn't you post this question already ? Don't double post. Anyway, here is the explanation again.

$string = file('test.php');

file() returns an array.

$strings=processFile($string);

You are passing an array as a parameter to the function processFile.

$lines = file($filename);

In function processFile, you are again trying to open an 'array' (instead of a file). Pass filename as a parameter for processFile function.

yes, but i was wondering maybe nobdy get my poin so im explaning in anohter way to understand, sory for that, I have alredy tried your replied but it doesnt work, it showing an erro desame with i got, thanks for replied again, :icon_confused:

What exactly are you trying to do with these 2 lines ?

$string = file('test.php');
$strings=processFile($string);

What exactly are you trying to do with these 2 lines ?

$string = file('test.php'); // $string is assign for the line of file. and

$strings=processFile($string); // this will get the line of string to return as an arry of string.

hope it now clear to you.

That is where you are going wrong. If you want a string use file_get_contents. file() returns an array.

ow; well that is another part for me to find out thanks, by the way, but can you give an exaple on how would i use the get_file_content to read the line of file?

Its in the link I have provided. $string = file_get_contents("test.php"); will read the entire file 'test.php' and returns it as a string.

This article has been dead for over six months. Start a new discussion instead.