widlguy Posted January 18, 2009 Share Posted January 18, 2009 I am trying to use this: <?php include($_SERVER['PHP_SELF'] . ".txt"); ?> To include a text file based upon the page name. The result gives me "/pagename.php.txt" instead of "pagename.php.txt". Giving me a failed to open error. Is there a better command line to use to accomplish this? Thanx in advance for any suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/141298-solved-code-question/ Share on other sites More sharing options...
Philip Posted January 18, 2009 Share Posted January 18, 2009 <?php $path = dirname(__FILE__); include $path.$_SERVER['PHP_SELF'].'.txt.'; ?> Should work. Quote Link to comment https://forums.phpfreaks.com/topic/141298-solved-code-question/#findComment-739557 Share on other sites More sharing options...
trq Posted January 18, 2009 Share Posted January 18, 2009 I believe the op is simply trying to remove the .php extension from $_SERVER['PHP_SELF']. <?php include substr($_SERVER['PHP_SELF'], 0, strlen($_SERVER['PHP_SELF']) -4) . ".txt"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/141298-solved-code-question/#findComment-739561 Share on other sites More sharing options...
Prismatic Posted January 18, 2009 Share Posted January 18, 2009 I believe the op is simply trying to remove the .php extension from $_SERVER['PHP_SELF']. <?php include substr($_SERVER['PHP_SELF'], 0, strlen($_SERVER['PHP_SELF']) -4) . ".txt"; ?> No The result gives me "/pagename.php.txt" instead of "pagename.php.txt" <?php include str_replace("/", "", $_SERVER['PHP_SELF']) .".txt"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/141298-solved-code-question/#findComment-739564 Share on other sites More sharing options...
trq Posted January 18, 2009 Share Posted January 18, 2009 Oh, guess I should read the questions closer next time huh? Quote Link to comment https://forums.phpfreaks.com/topic/141298-solved-code-question/#findComment-739566 Share on other sites More sharing options...
Philip Posted January 18, 2009 Share Posted January 18, 2009 It's not like you see a billion of them a day Quote Link to comment https://forums.phpfreaks.com/topic/141298-solved-code-question/#findComment-739568 Share on other sites More sharing options...
widlguy Posted January 18, 2009 Author Share Posted January 18, 2009 Thanx for the help! Worked right away. Quote Link to comment https://forums.phpfreaks.com/topic/141298-solved-code-question/#findComment-739829 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.