PHP File Loads Itself

This is weird idea I had right before I went to sleep last night. I might actually use it for something… have a look:

loadme.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
<?php
  $file = file_get_contents("loadme.php");
 
  $file = preg_split("/\?\>\n/", $file);
  $file = preg_replace("/^/m", "z",$file[1]);
 
  echo $file;
 
  die();
?>
one
two
three
four
 
'; ?>

The above just adds a z in front of each new line. So it outputs:

zone ztwo zthree zfour

It could be used for preprocessing a document. Something like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
<?php require_once("processor.php"); ?>;
 
html
  head
    meta charset="utf-8"
    title (test site)
 
  body
     #nav
       .btn(one) .btn(two) .btn(three)
 
     #left (left side)
 
     #center
        .entry
          h1(Hello This is an entry)
          (this is some text)
        .entry
          h1(Another Entry)
          (more text)
 
     #right (right side)
 
     #footer (Vorbin Saucer 2012)

The php would then turn the above markup into regular html. Kind of interesting…



 
 
 

One Response to “PHP File Loads Itself”

  1. cm
    13. October 2011 um 04:25

    Interesting idea for a simple templating engine! :)

Leave a Reply

Spam protection by WP Captcha-Free