BASIC to PHP sample

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jhendrickx
Forum Newbie
Posts: 3
Joined: Mon Jun 16, 2003 3:24 pm

BASIC to PHP sample

Post 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
Galahad
Forum Contributor
Posts: 111
Joined: Fri Jun 14, 2002 5:50 pm

Post 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.
corlando
Forum Newbie
Posts: 21
Joined: Sun Jun 15, 2003 10:07 pm

Post 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 
}			
?>
jhendrickx
Forum Newbie
Posts: 3
Joined: Mon Jun 16, 2003 3:24 pm

Post 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//
corlando
Forum Newbie
Posts: 21
Joined: Sun Jun 15, 2003 10:07 pm

Post by corlando »

no probem...glad i could help!
Post Reply