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!
I'm designing a site for a church and wanted to make it easy for them to update it so I don't have to do a lot of updating due to me doing this for free. I have the following code:
<?php
if ($handle = opendir('sermons')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "<a href='sermons/$file'>$file\n</a><br>";
}
}
closedir($handle);
}
?>
It will echo the filename plus the extension. (file.txt). How can I put it in here to exclude ".txt" from this, so it would just echo "file"? I'm doing this for the Pastor at the church who wants to make her weekly sermons available online by date. I'd rather it just say "September 29, 2010" instead of "September 20, 2010.txt". Thanks.
No problem.
str_replace function is also respectfull solution, actualy, it is bit faster than basename function, but not much.
If you ask me, i would go with basename function. It is more elegant and it's not such eye'stabing.
It tells you what is going on in code at first sight!
when an apostrophe ( ' ) is in the file name, it messes everything up. Any "shortcut" to searching the filename for an apostrophe and automatically putting in a "/" before it to make it easier?
PROBLEM SOLVED: LOOK AT POST BELOW FOR MY SOLUTION TO THIS APOSTROPHE "PROBLEM"!
Last edited by ZachsCompServ on Mon Aug 30, 2010 12:25 am, edited 1 time in total.
I'm a little confused by all of this. I'm going to get started on this later this week, but my idea is to have the links on the sermons.php page to link to a new page, sermons_open.php, that will have the filename after it (i.e. sermons_open.php?file=file, 08-30-2010.txt). The only thing is that I don't think spaces can be in the web address, even if it's in this form.
I'll get to work on it later this week as I said, and if I run into any problems I'll post it in a new thread. Just trying to find this topic in my php book and/or on the web. Just don't know what topic it would be under, but I do remember seeing this somewhere. Thanks