Jump to content

Recommended Posts

hi all;

 

        i ahve a functo read the file, but when itry to run it  I got an errro message. pls help with this. I got this error.

 

 

        Warning: file(<html>) [function.file]: failed to open stream: Invalid argument in F:\Program Files\Apache                                                  Group\Apache2\htdocs\chad folder\processlinestring\chadlib.php on line 36

 

Warning: Invalid argument supplied for foreach() in F:\Program Files\Apache Group\Apache2\htdocs\chad folder\processlinestring\chadlib.php on line 38

 

Fatal error: Function name must be a string in F:\Program Files\Apache Group\Apache2\htdocs\chad folder\processlinestring\chadlib.php on line 44

 

this is my function.

 

function processFile($filename) {

      $lines = file($filename);

$returnArray= array();

    foreach ($lines as $line) {

$output=processFile(trim($line));

if (gettype($output)=="array") {

$returnArray[]='<tr><td>Title:</td><td>'.($output[0]).'</td><td>Value:</td><td>'.$output[1].'</td></tr>';

}

}

return $returnArray();

}

 

 

this is how i test my function.

 

require_once('chadlib.php');

$strings=processFile("test.php");

echo '<table>';

foreach ($strings as $element => $value)

echo $value;

echo '</table>';

 

hope you guys can tell me where did got wrong in my code. thanks

Link to comment
https://forums.phpfreaks.com/topic/116154-how-can-i-fixed-this/
Share on other sites

why are you using recursion? is every line within your $filename a real path on the filesystem? i guess not as file(<html>) appears

 

try:

 

function processFile($filename) {
      $lines = file($filename);
     $returnArray= array();
      foreach ($lines as $line) {
          list($title, $value) = explode(",", $line);
              $returnArray[]='<tr><td>Title:</td><td>'.$title.'</td><td>Value:</td><td>'.$value.'</td></tr>';
           }      
        }
        return $returnArray;
     }

Link to comment
https://forums.phpfreaks.com/topic/116154-how-can-i-fixed-this/#findComment-597336
Share on other sites

hi all,

     

          well sory for my bad question, its my bad. by the way thanks for your  replied but it seems still have a problem. my only main goal is creat a function read a file. and I have this function to read the file. but I got an error message.

 

here is my error message.

 

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

            Warning: Invalid argument supplied for foreach() in

            Fatal error: Function name must be a string in.

 

and i have this code to read the file.

 

        function processFile($filename) {

      $lines = file($filename);

      $returnArray= Array();

  foreach ($lines as $line) {

$returnArray[]='<tr><td>Title:</td><td>'.($output[0]).'</td><td>Value:</td><td>'.$output[1].'</td></tr>';

}

    return $returnArray();

}

 

and this my test page.

 

      require_once('chadlib.php');

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

$strings=processFile($string);

echo '<table>';

foreach ($strings as $element => $value)

echo '<p>'.$value.'</p><br>';

echo '</table>';

 

Have another Idea where did I got wrong??

         

Link to comment
https://forums.phpfreaks.com/topic/116154-how-can-i-fixed-this/#findComment-597350
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.