peter_anderson Posted April 5, 2009 Share Posted April 5, 2009 Hi everyone, Im working on a mod for www.discussionscript.com, where it has articles. I've borrowed some code from their forum script. What it does is takes the name from the end of the url (eg article.php?a=hi) and includes the article name .txt from /articles directory (so ?a=hi would include ./articles/hi.txt) Here is my article.php code: <?php # Retrieve Theme $html = file_get_contents('./theme/theme.html'); $html = str_replace('{loginbar}', 'Please visit the forums to login', $html); $html = str_replace('{adminbar}', '', $html); $html = str_replace('{copyright}', 'Powered by <a href="http://www.discussionscript.com/cms.php">discussionSCRIPT CMS</a>', $html); $sArticleDirectory = './articles/'; $sArticleName = isset($_GET['a']) ? $_GET['a'] : 'default' ; $sArticleFile = $sArticleDirectory . $sArticleName . '.txt'; $html = str_replace('{content}', include($sArticleFile), $html); # Output Content echo $html; ?> However, it is not replacing {content} with the included file. Here is an example: http://www.thefitbaforum.com/article.php?a=test Anyone know how to fix it? It's probably a simple coding error. Thanks Link to comment https://forums.phpfreaks.com/topic/152642-str-replace/ Share on other sites More sharing options...
Mark Baker Posted April 5, 2009 Share Posted April 5, 2009 Better to use normal filesystem functions rather than include for a text file. Keep include() for php scripts, and use file_get_contents() for non-php files Link to comment https://forums.phpfreaks.com/topic/152642-str-replace/#findComment-801628 Share on other sites More sharing options...
peter_anderson Posted April 5, 2009 Author Share Posted April 5, 2009 Better to use normal filesystem functions rather than include for a text file. Keep include() for php scripts, and use file_get_contents() for non-php files Using file_get_contents fixed it Thanks. Link to comment https://forums.phpfreaks.com/topic/152642-str-replace/#findComment-801632 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.