<?php
require("util.class.php");
$util = new Util;
// All functions are separed by the function "line()"
function line(){echo "<br>".str_repeat("--",20)."<br>";}
function br(){echo "<br />";}
// dateDiff()
$date1 = "15-05-1960";
$date2 = "12-12-2009";
echo $util->dateDiff($date1,$date2) . " days";
line();
// calculateAge()
$myAge = $util->calculateAge("17/09/1990");
echo "I have ".$myAge." years old.";
line();
// days_actual_month()
$days_actual_month = $util->days_actual_month();
echo "This month have ".$days_actual_month." days.";
line();
// formatDateTime()
//Formats data coming from the database in the format YYYY-mm-dd hh:mm:ss
$dateToFormate = "2009-12-04 05:32:55";
$formatedDateOne = $util->formatDateTime($dateToFormate,1);
$formatedDateTwo = $util->formatDateTime($dateToFormate,2);
$formatedDateThree = $util->formatDateTime($dateToFormate,3);
echo "Date formated in action one: ".$formatedDateOne.".<br>";
echo "Date formated in action two: ".$formatedDateTwo.".<br>";
echo "Date formated in action three: ".$formatedDateThree.".<br>";
line();
// currentDay()
$currentDayPortuguese = $util->currentDay("pt");
$currentDayEnglish = $util->currentDay("en");
// Portuguese
echo "Hoje é: ".$currentDayPortuguese."<br>";
// English
echo "Today is: ".$currentDayEnglish."<br>";
line();
// dayWeek()
$oneDayPortuguese = $util->dayWeek("17","09","1990");
$oneDayEnglish = $util->dayWeek("17","09","1990","en");
// Portuguese
echo "Hoje é: ".$oneDayPortuguese."<br>";
// English
echo "Today is: ".$oneDayEnglish."<br>";
line();
// Discoment the lines bellow to see the javascript functions in action
// JavaScript Functions
$msg = "One or more errors appear.";
$page = "http://www.google.com/";
//$util->alert($msg);
//$util->alertBack($msg);
//$util->goBack();
//$util->closeWindow();
//$util->redirect($page);
//$util->update();
// no_injection_login()
$login = "' OR 'a'='a";
$pass = "' OR 'a'='a";
$anotherLogin = "zata";
$anotherPass = "1234";
$loginOne = $util->no_injection_login($login);
$loginTwo = $util->no_injection_login($pass);
$loginThree = $util->no_injection_login($anotherLogin);
$loginFour = $util->no_injection_login($anotherPass);
if(!$loginOne || !$loginTwo){
echo "First login doesn't passed.";
br();
} else {
echo "First login passed.";
}
br();
if(!$loginThree || !$loginFour){
echo "Second login doesn't passed.";
br();
} else {
echo "Second login passed.";
}
line();
// validateCpf
$validCpf = "17085303719";
$invalidCpf = "12345678909";
$validate1 = $util->validateCpf($validCpf);
$validate2 = $util->validateCpf($invalidCpf);
echo "The fisrt cpf ($validCpf) is: ";
echo $util->validateCpf($validCpf)==true ? "valid." : "invalid.";
br();
echo "The second cpf ($invalidCpf) is: ";
echo $util->validateCpf($invalidCpf)==true ? "valid." : "invalid.";
line();
// validateEmail()
$validEmail = "raul.3k@gmail.com";
$invalidEmail = "ra@ul@gmail.com";
echo "The first email is: ";
echo $util->validateEmail($validEmail)==true ? "valid." : "invalid.";
br();
echo "The second email is: ";
echo $util->validateEmail($invalidEmail)==true ? "valid." : "invalid.";
line();
// rewriteString()
// This function is to language with accents, portuguese in my case
$string = "Éssa função deve retirar os acentos e transforma-los em códigos html."; // English: This function should delete the accents and transforms them in html code.
echo $string;
br();
echo $util->rewriteString($string); // View the source to see the diferences
line();
// removeTags()
// This function is perfect to show titles of news, forums, where tags will confuse the source.
$strTags = "<i>Text with html tags</i><br /><b>This text are between tags</b>";
echo "With Tags:";
br();
echo $strTags;
br();
echo "No tags:";
br();
echo $util->removeTags($strTags);
line();
// leaveTags()
// I'll use the same variable I used previously
// I'll remove only the tag <i> first, and after I'll remove the tag <b>
echo "With all tags:";
br();
echo $strTags;
br();
echo "No <i>:";
br();
echo $util->leaveTags("i");
br();
echo "No <i>:";
br();
echo $util->leaveTags("b");
line();
// debugArray()
/**
* debugArray function use the print_r() function and show html tag <pre></pre> to show
* correctly in your screen
*/
$arrayTest = array("People"=>array("Name"=>"Raul","Age"=>19,"From"=>"Brazil"));
$util->debugArray($arrayTest);
line();
// limitPoint()
// This function limit point from number
$number = "156,556";
echo "Number: ".$number;
br();
echo $util->limitPoint($number,1);
br();
echo $util->limitPoint($number,2);
br();
echo $util->limitPoint($number,3);
br();
line();
// array_diff_values()
// This function delete repeated data in an array
$arrayTestDiff = array("Dog","Cat","Cow","Cat","Dog");
$newArrayTestDiff = $util->array_diff_values($arrayTestDiff);
echo "Original array:";
$util->debugArray($arrayTestDiff);
echo "Modified array";
$util->debugArray($newArrayTestDiff);
line();
// execPage()
// This function allow send parameters to an URL via post
$packet = array("name"=>"Raul");
$url = "http://www.exemple.com/";
$util->execPage($url,$packet);
/*
Exemple of www.exemple.com:
<?php
echo $_POST["name"]; // for test
?>
*/
?>
|