Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 13th, 2010, 12:14 AM
Registered User
 
Join Date: Mar 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in reading php file

hi all..clarify my code error..

in.php

<?php

$name=$_POST[nam];

echo $name;

?>

fileread.php

<?php

$fh=fopen("in.php"."r");

while(!feof($fh))

{

$line=fgtes($fh,100);

echo $line;

}

fclose($fh);

?>

Problem here is echo $line in fileread.php is not displaying any content if i give any text file as input it reads and displays the content.fileread.php doesn't read firstline of in.php i.e.,<?php

pl help me to run the above code successfully..

thanks in advance
 
Old March 13th, 2010, 04:45 PM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default fgets

You misspelled fgets, and the other thing is that, in fopen(), you used "." between parameters, which should really be ",". Enjoy!
Code:
<?php
	echo(getcwd());
	$fh=fopen("index.html","r");
	while(!feof($fh)) {
		echo(fgets($fh));
	}
	fclose($fh);
?>
 
Old March 13th, 2010, 08:56 PM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

It is always a good thing to check the return code from fopen. Hope this helps.
Code:
<html>
<body>
<?php
	echo(getcwd());
	$fh=fopen("index.htmll","r");
	if ($fh == FALSE) {
		echo("The file does not exist");
	} else {
		while(!feof($fh)) {
			echo(fgets($fh));
		}
		fclose($fh);
	}
?>
</body>
</html>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading Strings from Text File problem gian.sobhani C# 2005 1 August 31st, 2009 08:17 AM
Help with PHP file reading XML file for output rydog65 Beginning PHP 0 March 26th, 2008 05:13 PM
Problem in reading some part of a file denzil_cactus Perl 1 June 29th, 2007 09:29 AM
Capturing\Reading File Contents into DB with PHP aingalsbe PHP How-To 2 December 30th, 2005 09:48 AM
Problem with reading BAT file rhysduk VB How-To 0 January 12th, 2005 09:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.