LegosJedi Posted March 23, 2007 Share Posted March 23, 2007 Okay, so I've written my own template class, but for some reason, it's not replacing any of the keys in the templates. Here's the code for the template class: <?php class template { var $all = array(); var $tmpl_name; function output($filename, $existing = "", $replace = "") { //global $settings; //$file = $settings['siteroot'].$settings['tmpl_dir'].$this->tmpl_name.$filename.".tpl"; $file = CM_ROOT.$this->tmpl_name.$filename.".tpl"; if(!file_exists($file)) { echo '<b>Error:</b> Template file cannot be located.<br /><br /> We are trying to find <a href="'.$file.'">'.$file.'</a> in.<br /> <b>PROCESS SKIPPED.</b> <font color="red">Please notify the administrator about this problem.</font><hr />'; } else { $template = file_get_contents($file); $template = str_replace("{".$existing[$filename]."}", $replace[$filename], $template); $template = str_replace("{".$this->all['existing']."}", $this->all['replace'], $template); echo $template; } } } ?> When $existing and $replace are inputted, they're supposed to be arrays. Link to comment https://forums.phpfreaks.com/topic/43996-str_replace-no-replacing/ Share on other sites More sharing options...
monk.e.boy Posted March 23, 2007 Share Posted March 23, 2007 looks like it should work. Try putting some 'echo's in there to see the values. BTW get a good debugger for PHP, makes this sort of thing 10,000% easier to debug. I use NuSphere and it is cool. monk.e.boy Link to comment https://forums.phpfreaks.com/topic/43996-str_replace-no-replacing/#findComment-213625 Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 The curly braces may need to be escaped I believe, but yea try echoing the variables to make sure they contain what you expect. Link to comment https://forums.phpfreaks.com/topic/43996-str_replace-no-replacing/#findComment-213631 Share on other sites More sharing options...
LegosJedi Posted March 23, 2007 Author Share Posted March 23, 2007 Okay, I will. Thanks for the tips! Link to comment https://forums.phpfreaks.com/topic/43996-str_replace-no-replacing/#findComment-213633 Share on other sites More sharing options...
LegosJedi Posted March 23, 2007 Author Share Posted March 23, 2007 (Sorry for double post) Okay, I tried escaping the brackets, and that didn't work. Then I echoed the variables, and they all contained what they needed to contain. Any other tips? Link to comment https://forums.phpfreaks.com/topic/43996-str_replace-no-replacing/#findComment-213644 Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 I think you only would need to escape one bracket. I am not sure which but give that a try. Link to comment https://forums.phpfreaks.com/topic/43996-str_replace-no-replacing/#findComment-213648 Share on other sites More sharing options...
LegosJedi Posted March 23, 2007 Author Share Posted March 23, 2007 Nope. Still doesn't work. Link to comment https://forums.phpfreaks.com/topic/43996-str_replace-no-replacing/#findComment-213650 Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 Maybe try ereg_replace() http://us3.php.net/manual/en/function.ereg-replace.php Link to comment https://forums.phpfreaks.com/topic/43996-str_replace-no-replacing/#findComment-213658 Share on other sites More sharing options...
LegosJedi Posted March 23, 2007 Author Share Posted March 23, 2007 That somewhat worked. Some of the things that need to be displayed are displayed, but they aren't where they are supposed to be. Link Link to comment https://forums.phpfreaks.com/topic/43996-str_replace-no-replacing/#findComment-213672 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.