Text file - define Placeholder, read out via PHP - generate HTML/CSS on Webside -


i want put .txt file in folder on webserver.

via php want content of .txt file placed on startpage of webside.

the text file want code placeholders, form

[title]

lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam

[break]

[headline]

lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam

the placeholders should generate css or html of text automatically, [title] = h1 or [break] = < /br>

so question, how can it?

you need parse contents of file:

<?php $tokens = array(   'title'    => array('type' => 'multi-line', 'tag' => 'h1'),   'break'    => array('type' => 'single',  'tag' => 'br'),   'headline' => array('type' => 'single',  'tag' => 'hr') ); $currenttoken = null; // loop foreach (file('input.txt') $line) {   if(strlen($line)==0)//empty case     continue;   //check tags   if(preg_match('/\[(\w+)\]/', $line, $match)){     if(isset($tokens[strtolower($match[1])])) {       //multi-line case       if($currenttoken != null , $currenttoken['type'] == 'multi-line') {         echo "</{$currenttoken['tag']}>"; //close multi-line tag       }       $currenttoken = $tokens[strtolower($match[1])];       //single , multi-line       echo ( $currenttoken['type'] == 'single')?         "\n<{$currenttoken['tag']}/>": // print single tag         "<{$currenttoken['tag']}>"     //open multiline tag       ;     }   } else {     echo $line;   } } 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -