Hello,
I am working on a framework to write HTML pages in PHP. By that I mean a PHP class is responsible for creating HTML output, so you set up the inputs for the class instead of directly writing the HTML.
I was hoping I could get some feedback on the syntax, whether people think they would find it easy to use.
Here is an example, I will explain how it works afterwards:
<?php
p(0, 'html', ['lang', 'en-GB']);
p(1, 'head');
p(2, 'title', 'Example Page');
p(2, 'meta', ['name', 'description', 'content', 'An example page']);
p(2, 'meta', ['charset', 'utf-8']);
p(2, 'link', ['rel', 'icon', 'type', 'image/png', 'href', 'images/logo.png']);
p(2, 'link', ['href', 'css/standard-style.css', 'rel', 'stylesheet']);
p(1, 'body');
p(2, 'header');
p(3, 'img', ['src', 'images/logo.png', 'width', '200', 'alt', '']);
p(2, 'main');
p(3, 'h1', 'Example Page');
p(3, 'p', 'This is just an example page.');
p(3, 'h2', 'Look I can count!');
$countExample = '';
for ($i=1; $i<=25; $i+=1) {
$countExample .= $i;
if ($i != 25) {
$countExample .= ', ';
}
}
p(3, 'p', $countExample);
p(2, 'footer');
p(3, 'p', 'Where\'s My Shoe?');
?>
So the function can take up to 4 inputs.
- The first input must be the indentation as an integer. For each function call in relation to the last time the function was called, an increase of 1 indicates you want to add a child to the last element submitted, an increase of more than 1 throws an exception, if the indentation is the same as the last element, then the element is added as a sibling of the last element, and if there is a decrease, then the new element is added as a child of the last element of that level of indentation.
- The second input must be the element name as a string.
- The third and fourth inputs are optional. If you want your element to have child text, then the third input must be a string containing that child text. If you want to add attributes to your element, then the last input should be an array of strings in the order of attribute name, attribute value. You can add as many attributes as you want, and an array with a non-string, or an uneven number of inputs will throw an exception.
Please let me know what you think,
Many Thanks,
RT_