Warning: include_once(/home/llynix/llynix.com/wp-content/plugins/wordpress-support/wordpress-support.php): failed to open stream: Permission denied in /home/llynix/llynix.com/wp-settings.php on line 304

Warning: include_once(): Failed opening '/home/llynix/llynix.com/wp-content/plugins/wordpress-support/wordpress-support.php' for inclusion (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/llynix/llynix.com/wp-settings.php on line 304
Home » llynix.com

The One Line Template Engine

February 14th, 2010 @

Bought to you by vincevincevince over at webmasterworld.

The engine itself:
print preg_replace(“/\{([^\{]{1,100}?)\}/e”,”$$1″,file_get_contents(“template.tpl”));

Format of template.tpl file:

<html>
<head>
<title>{title}</title>
</head>
<body>
<h1>{header}</h1>
{text}
</body>
</html>

Setting variables:
$title=”Example page”;
$header=”My Examples”;
$text=”See the placeholders replaced?”;

“/\{([^\{]{1,100}?)\}/e”,”$$1″
I’m delimiting the regular expression with / / and using the modifier ‘e’ which causes the second argument to be evaluated by php.

Explanation


The pattern looks for an opening curly-brace ( \{ ) – the end of the pattern is a closing curly-brace ( \} ).

In between the two braces I look for any character which isn’t an opening curly-brace [^\{], avoiding mistaken nesting of tags.

I match between 1 and 100 of these non-{ characters by writing {1,100} and then I make the match non-greedy (try to find the shortest strings between { and }, not the longest) by adding a?. (? after *, + or {a,b} expressions changes them to non-greedy – in other situations? means 0 or 1 of the preceding).

The full string of non-{ characters is matched and stored as string $1 by surrounding that part of the pattern with brackets ().

Finally, the second argument of the preg_replace is “$$1”, using variable variables. If the pattern encounters “{title}” then the matched string $1 is “title” and so $$1 is $title.

Facebook Farmville HTML Fail

January 17th, 2010 @

Found this while playing on Facebook.facebook-farmville-html-not-accepted