Reputation: 3
<?
$file = ("file*");
$fp = fopen($file, 'a') or die("can't open file");
fwrite($fp, "testing");
fclose($fp);
?>
I want "testing" to be written to a file called file2.txt, but it instead writes to file*. I know that i can just set $file to "file2.txt", but this is just hypothetical.
Upvotes: 0
Views: 51
Reputation: 4592
I don't believe that globbing works the way you have it listed here. You could use the glob() function, which returns an array of matched filenames:
array = glob("file*")
I wouldn't recommend doing this, of course, because it's often hard to know that you'll only have a single file called file2.txt in the directory. If you do know that, it's better to specify explicitly, rather than using globbing.
That said, if you wanted to do things this way, that's how I would do it.
Upvotes: 3