Archive for the ‘PHP’ Category:
PHP Easter Egg / 1 April
Well, it just so happens that if you add this string :
?=PHPE9568F36-D428-11d2-A769-00AA001ACF42
at the end of any URL that is a PHP page (www.somewebsite.com/somephppage.php?=PHPE9568F36-D428-11d2-A769-0z0AA001ACF42) you will see a funny little picture of a dog.
for every version of PHP there is a difference image
For example: http://www.php.net/downloads.php?=PHPE9568F36-D428-11d2-A769-00AA001ACF42
Basically, every PHP expert know that there are 4 famous queries you can send to a PHP page:
Query 1 - ?=PHPE9568F36-D428-11d2-A769-00AA001ACF42
This is the most interesting and funny query, displays an funny image.
Query 2 - ?=PHPE9568F35-D428-11d2-A769-00AA001ACF42
Used by PHPINFO to show the Zend Logo, it will work on any php page
Query 3 - ?=PHPE9568F34-D428-11d2-A769-00AA001ACF42
Used by PHPINFO to show the Zend Logo, it will work on any php page.
Query 4 - ?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000
shows the PHP development credits.
Also, if you will look at the PHPINFO at 1 in April, the PHP Logo is replaced by the funny images above.
enjoy,
Aviv
PHP Casting problem in php4 and php5
PHP Casting problem in php4 and php5
In PHP4, We could CAST a variable like this:
class casttest {
function set_id($id) {
$this-> = $id;
}
}
$test1 = new casttest;echo (int) $test1, “\n”;As you probably guest, in PHP4 the result will be 1 because the variable we printed has a value,
On the other hand, in PHP5 we will receive this error:
Notice: Object of class Country could not be converted to integer in - on line X
And the value we will receive will be 1.
To solve this php version issue, all we have to do is add this:
zend.ze1_compatibility_mode = 1
Good luck,
Aviv.
Php Data Grid - 1
I couldn’t find a good php OS Data Grid Class, so let’s learn how to write one together.
1) The first step will be to create a new folder with the name “arpsdatagrid”
2) Create new file under “arpsdatagrid” folder with the name “arpsdgclass.php”
3) Lets start writing the file
Notes:
1) I’m writing this class with almost no ready made Array functions, just for best understanding of php.
2) There is a reason why i’m using the $dataheaders Array, it’s for future developing of our class.
<?php
class datagrid
{
var $datares; //Array of Data
var $cellsnum; //Size Of $datares
var $dataheaders; //Array of Data Headers
function datagrid($datares,$dataheaders)
{
$this->datares=$datares; //Setting Class Value
$this->cellsnum=sizeof($datares); //Setting Class Value
$this->dataheaders=$dataheaders; //Setting Class Value
return true;
}
function gettable() //Return String that contain table with all the Data
{
$array=$this->datares; //For easy use
$s=”<table border=1><tr>”; //Table Set
for($i=0;$i<sizeof($this->dataheaders);$i++) //get every header
{
$s.=”<td class=\”datagridheadertd\”>”.$this->dataheaders[$i].”</td> \n”;
}
$s.=”</tr>”;
for($i=0;$i<sizeof($array);$i++) //for every value at our Data Array
{
$s.=”<tr>”;
for($x=0;$x<sizeof($this->dataheaders);$x++) //Getting Data Headers
{
$s.=”<td>”.$array[$i][$this->dataheaders[$x]].”</td>”;
}
$s.=”</tr>”;
}
$s.=”</table>”;
return $s;
}
} //Closing the class
?>
How to use it?
Let’s say we have an Array named $array, the array contain
{
$array[0][’FNAME’]=’Aviv’;
$array[0][’LNAME’]=’Ronen’;
$array[1][’FNAME’]=’Aviv2′;
$array[1][’LNAME’]=’Ronen2′;
}
Basically, what we need to do is very simple:
1) $headersarray[0]=’FNAME’; //Setting the headers Array
$headersarray[1]=’LNAME’;
2) $datagrid=new datagrid($array,$headersarray); // Setting a Data Grid.
$tablegrid=$datagrid->gettable(); //Fetching the table string to $tablegrid
echo $tablegrid; //Printing the table string
The result will be:
| FNAME | LNAME |
| Aviv | Ronen |
| Aviv2 | Ronen2 |
Walla!
Enjoy!

