Jump to content

str replace


peter_anderson

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.