Page 1 of 1

BASIC to PHP sample

Posted: Mon Jun 16, 2003 3:24 pm
by jhendrickx
Hi friends, I think PHP is the greatest language right now; I know BASIC and I wrote a simple program, and I want to compare the BASIC program with a PHP program to learn how to do that using PHP, my basic program is this:

rem Ask for the name
input "Name: ",name$
rem open the file fro reading
open "myfile.txt" for output as #1
rem loop to read the whole file
while #1 <> eof
rem read a line
read #1,name1$,line$
rem compare the line with the supplied name, if is the same, show it
if name$=name1$ then print name$, line$
rem end the loop
wend
rem close the file
close #1

Thanks in Advance,
Jean

Posted: Mon Jun 16, 2003 6:24 pm
by Galahad
I'd start on the PHP manual. It's really well organized and usually includes helpful examples. I'm sure a quick google search for php tutorials would be informative, too. I don't know of any good tutorials off the top of my head, maybe someone else can point you to a good one.

Posted: Mon Jun 16, 2003 8:09 pm
by corlando
hope this helps you out...

Code: Select all

<!-- 
rem Ask for the name 
input "Name: ",name$
-->
<form action="" method="get" name="name" id="name">
  Name: 
  <input type="text" name="name">
  <input type="submit" name="Submit" value="Submit">
</form><?php

if ( isset($_GET['name']) && $_GET['name'] != "" ) {	

	//rem open the file for reading
	$fp = fopen("myfile.txt", "r");		// open "myfile.txt" for output as #1
	
	//rem loop to read the whole file 
	while( ! feof($fp) ) {				// while #1 <> eof 

		// rem read a line
		$line = fgets($fp);				// read #1,name1$,line$ 
		
		//rem compare the line with the supplied name, if is the same, show it 
		if ( strstr($line, $_GET['name']) )	// if entered name is in line then
			echo $line;						// print name$, line$ 
			
	}	// rem end the loop (wend)

	// rem close the file 
	fclose($fp); 			//close #1 
}			
?>

Posted: Wed Jun 18, 2003 4:59 am
by jhendrickx
Thanks Corlando, for me your example is worth than many manuals; although - of course - I'll dig on it; but the example is was I was needing, of curse still I have a lot of doubts, but now I know what's the general way of getting the thinks done in PHP. That's a great language!!

Jean H//

Posted: Wed Jun 18, 2003 5:27 am
by corlando
no probem...glad i could help!