gudfry Posted July 23, 2008 Share Posted July 23, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/116154-how-can-i-fixed-this/ Share on other sites More sharing options...
waynew Posted July 23, 2008 Share Posted July 23, 2008 Encapsulate your code in the code tag and people might try and help you. Quote Link to comment https://forums.phpfreaks.com/topic/116154-how-can-i-fixed-this/#findComment-597335 Share on other sites More sharing options...
ignace Posted July 23, 2008 Share Posted July 23, 2008 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; } Quote Link to comment https://forums.phpfreaks.com/topic/116154-how-can-i-fixed-this/#findComment-597336 Share on other sites More sharing options...
gudfry Posted July 23, 2008 Author Share Posted July 23, 2008 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?? Quote Link to comment https://forums.phpfreaks.com/topic/116154-how-can-i-fixed-this/#findComment-597350 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.