PHP File Template
From w3cyberlearnings
Contents |
PHP File Template
A text file can be used as a template.
File Content (book.txt)
This is a template text file that we are going to use with our template engine.
The book Infor: Author: {:author} Price: {:price} Publisher: {:publisher} Title: {:title} Info: {:body}
Example 1
Use str_replace() function to replace string within the template with the user define string.
<?php $file = 'book.txt'; $template_aa = array( '{:author}', '{:price}', '{:publisher}', '{:title}', '{:body}'); $array_aa = array( 'Jannifer Bill', 30, 'Orailly', 'PHP/MySQL', 'It\' a book for Web Developer and MySQL'); if (file_exists($file)) { $file_content = file_get_contents($file); $fin_content = str_replace($template_aa, $array_aa, $file_content); print nl2br($fin_content); } ?>
Output
The book Infor: Author: Jannifer Bill Price: 30 Publisher: Orailly Title: PHP/MySQL Info: It' a book for Web Developer and MySQL