Php2Html - Write HTML using only php

Write HTML using only php


"Use multiple sources to build your page"
««Tags | Controls | HTML Events | Importing files | Database Integration | Database Web »»

how to


invoking the class

First we need include the PHP2HTML class file. And create the instance of the class. In this case $p is the instance of our class.

01: include_once 'html.class.php'; 02: $p = new PHP2HTML();

including files:

The method CSS() imports and include a CSS file into the header page. Then the method HTML() includes an html file called table.html. With this method is posible to include plain text or html files. You can also include javascript into the header or anywhere on the page, also php files could be executed and included.

For style sheets and JavaScript libraries do not need to put them at the top of the page, because with these methods JS() and CSS() always be included in the header.

But it is great to always keep a correct structure of the page to make maintenance easier. There is no limit to the number of files that can be included.

03: $p->CSS('css/styles.css'); ... ... 06: $p->HTML('contents/table.html');

adding text, comments and controls:

The method Body() adds the contents of a variable to the body in the sequence defined as statements that go entering the user. This method can receive content from other methods such as Link(), which in this case,creates a link to Google website or the Btn() method, which inserts a button on the page, which they have defined the onClick() event and execute javascript code.

04: $p->Body('<div>Hello World</div>'); ... 08: $p->Body($p->Link(PAGEF, "","Google","_blank"'));

And finally the method Create() returns the HTML page.

01: include_once 'html.class.php'; 02: $p = new PHP2HTML(); 03: $p->CSS('css/styles.css'); 04: $p->Body('<div>Hello World</div>'); 05: $p->Comment("Begin of imported file"); 06: $p->HTML('contents/table.html'); 07: $p->Comment("End of imported file"); 08: $p->Body($p->Link(PAGEF, "","Google","_blank"')); 09: $p->HTMLbr(); 10: $p->Body( 11:         $p->Btn( 12:                 "button", "Click Me", "myClass", "myID", "myName", 13:                 actions::onClick( 14:                         "alert('Hello'); return false;") 15:                 ) 16: ); 17: $p->Create();

resulting code

01: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 02: ""> 03: <html lang="en"> 04: <head> 05: <title>PHP2HTML</title> 06: <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 07: <meta name="title" content="PHP2HTML"> 08: <meta name="keywords" content="PHP2HTML, Class, Web, Vista, Controller, Framework, MySQL, Oracle, MSSQL"> 09: <meta name="description" content="Library that allows you to write html pages using only PHP code"> 10: <meta name="author" content="My name"> 11: <meta name="robots" content="INDEX,FOLLOW"> 12: <link type="text/css" rel="stylesheet" href="css/styles.css"> 13: </head><body class=""> 14: <div>Hello World</div> 15: <!--Begin of imported file--> 16: <table border="1" cellpadding="1" cellspacing="1"> 17:     <thead> 18:     <tr> 19:         <th>Title 1</th> 20:         <th>Title 2</th> 21:         <th>Title 3</th> 22:         <th>Title 4</th> 23:         <th>Title 5</th> 24:     </tr>     25:     <tr> 26:         <th colspan="5" align="center">A nice table</th> 27:     </tr> 28:     </thead> 29:     <tbody> 30:     <tr> 31:         <td>Row 1</td> 32:         <td>Row 2</td> 33:         <td>Row 3</td> 34:         <td>Row 4</td> 35:         <td>Row 5</td>             36:     </tr> 37:     <tr> 38:         <td colspan="5" align="center"><a href="" target="_blank">Click to access</a></td>             39:     </tr>         40:     <tr> 41:         <td>Row 1</td> 42:         <td>Row 2</td> 43:         <td rowspan="3">Row</td> 44:         <td>Row 4</td> 45:         <td>Row 5</td>             46:     </tr> 47:     <tr> 48:         <td>Row 1</td> 49:         <td>Row 2</td> 50:         <td>Row 4</td> 51:         <td>Row 5</td>             52:     </tr> 53:     <tr>             54:         <td>Row 1</td> 55:         <td>Row 2</td> 56:         <td>Row 4</td> 57:         <td>Row 5</td>             58:     </tr>     59:     </tbody> 60:     <tfoot> 61:         <tr> 62:             <td colspan="5" align="right"><strong>Table Footer</strong></td> 63:         </tr> 64:     </tfoot>     65: </table> 66: <!--End of imported file--> 67: <a href="" target="_blank" >Google</a> 68: <br> 69: <button type="button" class="myClass" id="myID" name="myName" onclick="alert('Hello'); return false;">Click Me</button> 70: </body> 71: </html>

Note: The META tags, title, doc type and lang are defined in the html.def.php file. But its posible to change those attributes using the method Set_Meta()