<?php
$array = array (
array (
),
array (
array (
)
)
);
function bindArrayToObject($array) {
$return = new stdClass();
foreach ($array as $k => $v) {
if (is_array($v)) {
$return->$k = bindArrayToObject($v);
}
else {
$return->$k = $v;
}
}
return $return;
}
$newObject = bindArrayToObject($array);
print_r($newObject);
?>
Tag Archive for php
Convert Array to Object, infinite dimensions
Show Current Date
<?php
// Value of how many hours offset from server and local time
$hourdiff = "3";
// Offsetting time by seconds
$timeadjust = ($hourdiff * 3600);
// Format of date which will be displayed
$currentdate = date("l m/d/y",time() - $timeadjust);
// Display the output
print ("$currentdate");
?>
all available date info
<?php
class dayInfo {
private $date = false;
public $dateInfo = stdClass;
public function __construct($dateArray = "") {
$this->dayInfo($dateArray);
}
public function dayInfo($dateArray = "") {
if (is_array($dateArray)) {
$this->date = mktime(
$dateArray["hour"],
$dateArray["minute"],
$dateArray["second"],
$dateArray["month"],
$dateArray["day"],
$dateArray["year"],
$dateArray["isDST"]
);
}
else {
if ($dateArray != "") {
$this->date = strtotime($dateArray);
}
else {
$this->date = time();
}
}
$this->getDateInfo();
}
private function getDateInfo() {
if ($this->date !== false) {
$return = array (
"day" => array(
"d" => date("d", $this->date),
"D" => date("D", $this->date),
"j" => date("j", $this->date),
"l" => date("l", $this->date),
"N" => date("N", $this->date),
"S" => date("S", $this->date),
"w" => date("w", $this->date),
"z" => date("z", $this->date)
),
"week" => array (
"W" => date("W", $this->date)
),
"month" => array (
"F" => date("F", $this->date),
"m" => date("m", $this->date),
"M" => date("M", $this->date),
"n" => date("n", $this->date),
"t" => date("t", $this->date)
),
"year" => array (
"L" => date("L", $this->date),
"o" => date("o", $this->date),
"y" => date("y", $this->date),
"Y" => date("Y", $this->date)
),
"time" => array (
"a" => date("a", $this->date),
"A" => date("A", $this->date),
"B" => date("B", $this->date),
"g" => date("g", $this->date),
"G" => date("G", $this->date),
"h" => date("h", $this->date),
"H" => date("H", $this->date),
"i" => date("i", $this->date),
"s" => date("s", $this->date)
),
"timezone" => array (
"e" => date("e", $this->date),
"I" => date("I", $this->date),
"O" => date("O", $this->date),
"P" => date("P", $this->date),
"T" => date("T", $this->date),
"Z" => date("Z", $this->date)
),
"full" => array (
"c" => date("c", $this->date),
"r" => date("r", $this->date),
"U" => date("U", $this->date)
)
);
$this->dateInfo = $this->bindArrayToObject($return);
}
else {
$this->dateInfo = false;
}
}
private function bindArrayToObject($array) {
$return = new stdClass();
foreach ($array as $k => $v) {
if (is_array($v)) {
$return->$k = $this->bindArrayToObject($v);
}
else {
$return->$k = $v;
}
}
return $return;
}
}
$dayInfo = new dayInfo();
print_r($dayInfo);
?>
php based access blocking
<?php
$blocker_isBlocked_redirect = "http://www.mechanicmatt.com/Access+Denied-p71.html";
$blocker_isBlocked_return = "||{{{error}}}||";
$blocker_isBlocked_err_msg = "You have been temporarily blocked from accessing this content.";
//blocking class
class blocker {
var $ips = NULL;
var $domains = NULL;
var $currentEnv = NULL;
var $blocked = NULL;
var $redirect = NULL;
function blocker($env, $redirect = true) {
$this->ips = array (
//"67.191.103.115"
);
$this->domains = array (
//"nefec.org"
);
$this->blocked = false;
if (is_null($redirect)) {
$this->redirect = true;
}
else {
$this->redirect = $redirect;
}
$this->currentEnv = $env;
}
function isBlocked() {
global $blocker_isBlocked_redirect;
$this->checkIP();
$this->checkHostname();
if ($this->blocked == true && $this->redirect == true) {
header("Location: " . $blocker_isBlocked_redirect);
}
else {
return $this->blocked;
}
}
function checkIP() {
if (in_array($this->currentEnv["REMOTE_ADDR"], $this->ips)) { //check for exact match
$this->blocked = true;
}
else { //exhaustive partial match
foreach ($this->ips as $ip) {
if (ereg("^(".$ip.")", $this->currentEnv["REMOTE_ADDR"])) {
$this->blocked = true;
}
else {
}
}
}
}
function checkHostname() {
$userHostName = gethostbyaddr($this->currentEnv["REMOTE_ADDR"]);
foreach ($this->domains as $k => $v) {
if (eregi($v, $userHostName)) {
$this->blocked = true;
} else {}
}
}
}
$blocker = new blocker($_SERVER, $redirect);
$blocker_isBlocked = $blocker->isBlocked();
?>
simple security for external included files
Inside your parent file (that does the including), place this at the top
define("parentFile", 1);
and then at the top of all of your php parsed include files, place this
if(defined("parentFile") === true) {
die("direct access is not allowed");
} else {}
so in your directory you have index.php (parent file) and "pages.php" (include file), if you went directly to yourdomain.com/pages.php, it wont results in PHP errors, it will simply die with that error message.
To test, go to <a href="http://www.mechanicmatt.com/bp/" >http://www.mechanicmatt.com/bp/</a>
and then go to <a href="http://www.mechanicmatt.com/bp/pages.php
" >http://www.mechanicmatt.com/bp/pages.php
source
read XML with PHP
//xml.xml :
<?xml version="1.0" encoding="utf-8" ?>
<Kategorien>
<Kategorie>
<ID>1</ID>
<Name>PHP</Name>
<link>http://www.tsql.de/php.php</link>
</Kategorie>
<Kategorie>
<ID>2</ID>
<Name>SQL</Name>
<link>http://www.tsql.de/transact-sql/howto.htm</link>
</Kategorie>
<Kategorie>
<ID>3</ID>
<Name>CSharp</Name>
<link>http://tsql.de/csharp.htm</link>
</Kategorie>
</Kategorien>
//xmlread.php :
$Kategorien = simplexml_load_file('php-xml-lesen.xml');
echo $Kategorien->Kategorie[0]->Name.'<br />';
echo $Kategorien->Kategorie[0]->ID.'<br />';
echo $Kategorien->Kategorie[0]->link.'<br />';
Crear una lista de carpetas con PHP
<?php // Crear una lista de carpetas con PHP
echo "<h3>Index</h3>
";
echo "<table>
";
$directorio = opendir(".");
while ($archivo = readdir($directorio))
{
$nombreArch = ucwords($archivo);
$nombreArch = str_replace("..", "Atras", $nombreArch);
echo "<tr>
<td>
<a href='$archivo'>
";
echo "<img src='ico_folder.gif' alt='Ver $nombreArch'";
echo " border=0>
";
echo "<b> $nombreArch</b></a></td>
";
echo "
</tr>
";
}
closedir($directorio);
echo "</table>
";
?>
Category: Uncategorized |
Tags: php
Imprimir la fecha en español utilizando PHP aunque el idioma del servidor sea el inglés.
/*************************************
Devuelve una cadena con la fecha que se
le manda como parámetro en formato largo.
*************************************/
function FechaFormateada2($FechaStamp)
{
$ano = date('Y',$FechaStamp);
$mes = date('n',$FechaStamp);
$dia = date('d',$FechaStamp);
$diasemana = date('w',$FechaStamp);
$diassemanaN= array("Domingo","Lunes","Martes","Miércoles",
"Jueves","Viernes","Sábado"); $mesesN=array(1=>"Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio",
"Agosto","Septiembre","Octubre","Noviembre","Diciembre");
return $diassemanaN[$diasemana].", $dia de ". $mesesN[$mes] ." de $ano";
}
//Para utilizar la función, se le manda una fecha como parámetro, por ejemplo, si se quisiera imprimir la fecha actual, utilizarÃamos el siguiente código:
$fecha = time();
echo FechaFormateada2($fecha);
Category: Uncategorized |
Tags: php
PHP HOOK for Accrisoft Freedom
<?
if (($_REQUEST['src'] == 'jobs') && ($_REQUEST['srctype'] == '')) {
?>
<style type="text/css">
table.job_listings {display: none;}
</style>
<?
}
?>