regex – template var

http://www.phpro.org/tutorials/Introduction-to-PHP-Regex.html

<?php

// create a string with some template vars. the string and
// the vars would easily have been called from a template.
$string = 'This is the {_FOO_} bought to you by {_BAR_}';

// create an array of template vars
// of course, each variable could be an array itself
$template_vars=array("FOO" => "The PHP Way", "BAR" => "PHPro.orG");

// preg replace our variables and evaluate them
$string = preg_replace("/{_(.*?)_}/ime", "\$template_vars['$1']",$string);

// echo the new string
echo $string;

?>

Published by

G3n1k

just to remember what i had known :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s