How to use and parse custom user input variables %var% with PHP?
I want to enter some 开发者_如何学JAVAnews into my website and enter a variable like %custom_heading% and get PHP to replace this with the custom heading I have set, this allows me to enter it in wherever I want, how would I go about doing this?
Update: Thanks this helped a lot :) Already in my code now.
Very simple use str_replace
on the string...
$vars = array(
'name' => 'Joe',
'age' => 10
);
$str = 'Hello %name% you are %age% years old!';
foreach ($vars as $key => $value) {
$str = str_replace('%' . $key . '%', $value, $str);
}
echo $str; // Hello Joe you are 10 years old!
精彩评论