PHP Classes

File: example2.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Classes of Fauzi Gomez  >  Easy HTML Class  >  example2.php  >  Download  
File: example2.php
Role: Example script
Content type: text/plain
Description: New example file
Class: Easy HTML Class
Compose HTML tags programatically
Author: By
Last change: it was an error in the last file, fixed, no a very important one but it is better this way
Date: 1 year ago
Size: 6,182 bytes


Class file image Download
<!DOCTYPE html>

include ("html.class.php");

//in this var we are going to save all our html output for later run a simple echo
$output = "";

//Here we are going to save all the head
$head = "";

//Here we are going to save all the body content
$body = "";

/********* Some content Text ***********/
$some_text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam sed cursus eros. Vivamus placerat elit id lectus scelerisque pharetra.
            Proin blandit ut sapien eget imperdiet. Sed lorem neque, gravida at elementum vitae, tincidunt sit amet ante.
            Quisque consequat felis ut libero eleifend lacinia. Phasellus dignissim orci a lorem scelerisque feugiat.
            Vestibulum ipsum quam, vehicula nec diam sit amet, feugiat volutpat nisl. Mauris sed lorem vitae libero blandit adipiscing ac a dui.
            Praesent venenatis lorem a velit tristique, eget aliquam neque aliquam. Etiam mattis tristique arcu sed ultrices. Integer condimentum sit amet nibh in malesuada."
$other_text = "Suspendisse ac varius est. Phasellus elit orci, euismod a elementum vel, mollis ut elit. Aliquam egestas pharetra libero et tempor. Sed a lorem nibh.
            Curabitur ac ornare lorem, id dictum ipsum. Phasellus molestie aliquet ipsum at facilisis. Sed eu imperdiet elit, eget lacinia augue.
            Vivamus sodales justo id quam vehicula viverra. Sed eget felis id ligula mattis imperdiet facilisis vehicula dolor.
            Aliquam lorem sem, ullamcorper nec turpis eget, posuere congue diam. Aliquam lobortis quam in laoreet pretium. Cras auctor nisi eget auctor malesuada. "
$line_text = "A Simple Line text";

/********** Some basic ojects we are going to asociate later to some tags *************/

//this is a simple json in string form
$basic_input_type_text = '{"class":"simple_input","placeholder":"Some Text"}';
$basic_input_type_text = json_decode($basic_input_type_text);

//another kind of object
$standar_class_object = new stdClass();

$standar_class_object->id = 'simple';
$standar_class_object->name = 'simple';

//another kind of object
$simple_class = array();

$simple_class['class'] = 'extra_simple';

//Lets beging

//Let's create the header

$some_meta = '{"1":{"http-equiv":"content-type","content":"text/html; charset=utf-8"},"2":{"name":"robots","content":"index, follow"},"3":{"name":"keywords", "content":"Just an Example"}}';
//$some_meta = '{{"http-equiv":"content-type","content":"text/html; charset=utf-8"},{"name":"robots","content":"index, follow"},{"name":"keywords", "content":"Just an Example"}}';

//let's convet the json into an object, the index in this case do make any difference
$some_meta = json_decode($some_meta);


foreach($some_meta as $key=>$value){
$head .= html::metaFromObj($value);


//Now let's create some link, you can make reference to a css file, but in this example we are only linking a favico

$some_head_link = array('href'=>'', 'rel'=>'shorcut icon', 'type'=>'image/x-icon');

$head .= html::headLinkFromObj($some_head_link);

//Now let's create some scripts

$some_head_script = new stdClass();

$some_head_script->type = 'text/javascript';

$head .= html::scriptFromObj($some_head_script, 'function hola(){alert (\'hola\');}');

//The is no head function in the class, so we are going to finish the header now

//let's create a title
$title = '<title>Create HTML without the HTML</title>';
$head .= $title;

$head = '<head>'.$head.'</head>';

//Now Let's start the body

//Now we are focusing on the tags body or values, some objects are otional because sometimes we do add any extra arguments
$some = html::h1FromObj("This is the biginning");

$some .= html::hFromObj(3, "Somethimes we really wan to add a clas or an id", $simple_class);

$body .= html::divFromObj($some,array('id'=>'body_header'));

$some = html::pFromObj(array('id'=>'some_p','value'=>$some_text,'style'=>'padding: 10px 0;color: blue;'));

$body .= html::divFromObj($some,$simple_class);

//Let's create a list
$some = "";
for (
$i = 0; $i <10; $i++){
$puit = $line_text.' '.$i;
$some .= html::liFromObj($puit);

$some = html::ulFromObj($some);

//append our progress to the body
$body .= html::divFromObj($some);

$some = html::hFromObj(1, "What about inputs and buttons?");

//append our progress to the body
$body .= html::divFromObj($some);

$input_arguments = $basic_input_type_text;
$input_arguments->label = 'Input 1: ';
$input_arguments->id = 'inpuit_texto';

$input = html::inputFromObj($input_arguments);
$input = html::divFromObj($input);

$sapo[] = '---- Select One ----';

$i =0; $i < 7; $i++){
$sapo['value'.$i] = "Select ".$i;

//when create the select let's preselect the third value
$select = html::selectFromObjs($sapo, array('id'=>'id_select', 'label'=>'Select some','selected'=>3));
$select = html::divFromObj($select);

$radio1 = html::radioFromObj(array('id'=>'some_name','name'=>'some_name','value'=>'some_value','label'=>'First Radio: '));

$radio2 = html::inputFromObj(array('id'=>'other_name','type'=>'radio','name'=>'other_name','value'=>'some_value','label'=>'Second Radio: '));

$standar_class_object->value = 'Hit Me';
$standar_class_object->onclick = 'hola()';

$button = html::buttonFromObj($standar_class_object);

//now lets group all out inputs

$legend = html::legendFromObj('Group of inputs');

$inputs = html::fieldsetFromObj($legend.$input.$select.$radio1.'<br/>'.$radio2.'<br/>'.$button,array('style'=>'backgorund: #CCCCCC;'));

$form = html::formFromObj($inputs, array('action'=>'#'));

//append our progress
$body .= html::divFromObj($form);

//let's end our site
$body = html::bodyFromObj($body);

$output = html::createHtml($head.$body);