Sanjib Sinha Posted December 29, 2008 Share Posted December 29, 2008 I have two php pages titled index.php and method1.php code of method1.php is <?php function s($file = "myfile.html") { return ("$file"); } ?> and the code of index.php is <?php include ("method1.php"); ?> <?php echo s(readfile("myfile.html")); ?> The problem is readfile as a function executes fine but at the end a number 347 has come up. Why this happens? Secondly, can any one tell me whether reading or writing file as function can be done this way, or it is wrong? Quote Link to comment Share on other sites More sharing options...
opalelement Posted December 29, 2008 Share Posted December 29, 2008 I personally would use require instead of include. I use include when it is something that will display data and require when it is only functions. I think they are the same though, except for how they handle errors. I also wouldn't use a file per function. I would make functions.php and put multiple ones in there. The 347 sounds like something to do with the file. What is in myfile.html? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted December 29, 2008 Share Posted December 29, 2008 The 347 is from readfile(). readfile() returns an integer representing the number of bytes read in. I don't understand the point of s() though... Quote Link to comment Share on other sites More sharing options...
opalelement Posted December 29, 2008 Share Posted December 29, 2008 I assumed the s() had more data in it that he took out Quote Link to comment Share on other sites More sharing options...
btherl Posted December 29, 2008 Share Posted December 29, 2008 Try file_get_contents() instead of readfile(), if you want the contents of the file as a return value. Quote Link to comment Share on other sites More sharing options...
Sanjib Sinha Posted December 29, 2008 Author Share Posted December 29, 2008 The 347 is from readfile(). readfile() returns an integer representing the number of bytes read in. I don't understand the point of s() though... 's' is a function here. I wanted to put html file in variable! Quote Link to comment Share on other sites More sharing options...
Sanjib Sinha Posted December 29, 2008 Author Share Posted December 29, 2008 Try file_get_contents() instead of readfile(), if you want the contents of the file as a return value. file_get_contents is working perfectly. Number has vanished. thanks. Quote Link to comment 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.