Reputation: 53
VERY simple routine that pulls the name of each PDF file in a folder and creates a list of each file found with a link to it. But I cannot get a line break between the items
Nothing seems to give me each file name and link on a new line. I have no idea why.
Neither of the \n has any affect at all.
<?php
$directory = "./images/";
$phpfiles = glob($directory . "*.pdf");
foreach($phpfiles as $phpfile)
{
echo "\n","<a href=$phpfile>".basename($phpfile)."</a>";
echo "\n";
}
?>
All I get for output is this....all on one line.
CAD_REPEQUEST.pdf JP_CADS.pdf JP_Reports.pdf
What I want is this....
CAD_REPEQUEST.pdf
JP_CADS.pdf
JP_Reports.pdf
Upvotes: 1
Views: 42
Reputation: 4043
If you're outputting to a Web page you'll need to replace \n
with <br>
.
If you're outputting to a text or other type of file, you may wish to replace \n
with the constant PHP_EOL
.
If you're outputting this to an email that's getting sent in text format, you'll have trouble with some clients, like Outlook, that will automatically attempt to remove unnecessary line breaks. Sometimes using a double line break helps, or you could convert your email to HTML and use the <br>
approach.
Upvotes: 3