Using php oncli few questions ~ using XAMPP

deepuraj

New Member
Attempting to expand my knowledge by using PHP on the Command Line.Currently I have a default installation of XAMPP, and have set up my Environment Variable.I've been able to execute simple scripts like:\[code\]<?php echo 'hello world!'; ?>\[/code\]Questions ~Where do I store the scripts I am using? Currently I am doing:C:\Users\Ross>php c:\helloworld.phpit works. Does this mean I need to specify a path every time? Or should I store php files inside my c:>xampp\php directory? I tried this and it doesn't appear to work.What would be the accepted "best practice".2nd questionCould someone explain why this doesn't work:\[code\] <?php fwrite(STDOUT, "Enter file name:\n"); $file=fgets(STDIN); print 'you entered...' . $file; $fp=fopen($file,'r'); if(!$fp) { print 'File could not be opened..'; } else { /* show file pointer */ print($fp); } ?>\[/code\]and then I do:\[code\]C:\Users\Ross>php c:\file.phpEnter file name:c:\foo.txtyou entered...c:\foo.txtWarning: fopen(c:\foo.txt): failed to open stream: Invalid argument in C:\file.php on line 6File could not be opened..\[/code\]"foo.txt" is in the same directory and does exist.thanks for any clarification.
 
Back
Top