str_replace (or another option) for replacing content located inside a php document -
i'm attempting make template file cms i'm making template file can contain variables {username}
regular text replaced when page gets included on index.php page.
example: index page:
<?php include('templates/123/index.php'); ?>
templates/123/index.php page
<?php include('header.php'); ?> welcome {username} <?php include('footer.php'); ?>
i've tried several methods; however, run problems because page i'm trying change content on includes php code. every method try either 1) messes because opening , closing of php tags within document or 2) echoes out php code in document. there way can still achieve this? maybe class of kind? want able achieve safely.
i using custom variables {content1} replaces php code ioncubed retrieves data database content located in column1, same {column2} {column3} , {column4}. i'm trying make creation of templates extremely easy. (so i'd make code work well)
my preferred method of doing stuff involves starting code with:
ob_start(function($c) { $replacements = array( "username"=>"kolink", "rank"=>"awesome" ); return preg_replace_callback("/{(\w+)}/",function($m) use ($replacements) { return isset($replacements[$m[1]]) ? $replacements[$m[1]] : $m[0]; },$c); });
Comments
Post a Comment