Trabla: php: create and write to file
Solving:
File test.php
<?php
$rows = array( 'New York' , 'London', 'Odessa' );
$file = fopen("C:\myfolder\cities.txt","w") or die("Can't open file");
foreach( $rows as $row){
$str = $row . "\n";
fwrite( $file, $str );
}
fclose( $file );
?>
Run via Windows CMD:
1. Open cmd
2. Run command:
CD C:\myfolder\
3. Run command:
php test.php
No comments:
Post a Comment