konetch Posted April 9, 2009 Share Posted April 9, 2009 I have this so far <?php $dir = str_replace('/', '', __DIR__); switch($dir) { case 'travel': echo '<div id="top">'; break; case 'sports': echo '<div id="top1">'; break; case 'politics;': echo '<div id="top2">'; break; case 'submit': echo '<div id="top3">'; break; case 'links': echo '<div id="top3">'; break; case 'column': echo '<div id="top3">'; break; case 'funny': echo '<div id="top3">'; break; default: echo '<div>'; } ?> I want all the files in the directory shown in the case what I have. I want all files in the directory 'travel' to have '<div id="top">' appear in the source code of all files within the directory 'travel'. This doesn't work though. Does anybody have any idea how to fix this? Quote Link to comment https://forums.phpfreaks.com/topic/153370-all-files-in-directory-switch/ Share on other sites More sharing options...
Maq Posted April 9, 2009 Share Posted April 9, 2009 Echo out $dir to make sure it matches something, or have a default case. Quote Link to comment https://forums.phpfreaks.com/topic/153370-all-files-in-directory-switch/#findComment-805774 Share on other sites More sharing options...
konetch Posted April 9, 2009 Author Share Posted April 9, 2009 I'm still really new to php, so I don't understand everything your saying. I have a default case, and I'm not sure what you mean by echo out $dir. Quote Link to comment https://forums.phpfreaks.com/topic/153370-all-files-in-directory-switch/#findComment-805779 Share on other sites More sharing options...
Maq Posted April 9, 2009 Share Posted April 9, 2009 What exactly happens when you run the script? $dir = str_replace('/', '', __DIR__); echo "This is my dir: " . $dir; switch($dir) Quote Link to comment https://forums.phpfreaks.com/topic/153370-all-files-in-directory-switch/#findComment-805781 Share on other sites More sharing options...
konetch Posted April 9, 2009 Author Share Posted April 9, 2009 It just displays the default case. No errors or anything show up Quote Link to comment https://forums.phpfreaks.com/topic/153370-all-files-in-directory-switch/#findComment-805783 Share on other sites More sharing options...
Maq Posted April 9, 2009 Share Posted April 9, 2009 What does it output when you echo $dir? Quote Link to comment https://forums.phpfreaks.com/topic/153370-all-files-in-directory-switch/#findComment-805785 Share on other sites More sharing options...
konetch Posted April 9, 2009 Author Share Posted April 9, 2009 On the top of my screen where the div tag should be it displays.. This is my dir: __DIR__ Quote Link to comment https://forums.phpfreaks.com/topic/153370-all-files-in-directory-switch/#findComment-805789 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.