Category: PHP

  • The One Line Template Engine

    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 […]

  • Javascript Countdown with PHP Fall Back

    Perhaps you have an event that happens on your webpage at a certain time, or you want to give a countdown to when the world ends. With this piece of JavaScript you can do this, and a PHP fall back will allow non JavaScript enabled browsers to still view the relevant information. Let’s start with […]