Post your trick

explicitly call super class constructor in php

Unlike Java , the constructor of the super class will not be called implicitly in PHP .

To call the parent class constructor from the child class we can use :

parent::construct();


Adding date and time in PHP

I came across a situation where i want to end an event exactly after two days and before an hour of third day ( i.e. 11:00 pm on third day). After searching on google and checking the date function in php manual i came to this solution

$new_date = ( strtotime(’-1 hour’,strtotime ( ‘+3 day’ , strtotime (date ( ‘Y-m-d’ ) ) ) ));

This will return a unix timestamp which will give you 11:00 pm of third day.
eg. if todays date is 27/05/2010 07:08:15 then it will give you 29/05/2010 23:00:00


Inserting multiple values from a listbox into the database

if you have a listbox called “department” and want to insert multiple values from the listbox into the database,then:
when the user submits the form,store the value in a variable
$company_dept=$_POST['department'];
query:INSERT into table_name values(’”.join(”,”,$company_dept).”‘)


Email check in php
function isValidEmail($email){
return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]
+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
}

Make your css dynamic

To implement constants in css , let your php script output as css by passing the following headers :

header(’content-type:text/css’);
header(”Expires: “.gmdate(”D, d M Y H:i:s”, (time()+900)) . ” GMT”);


Post A Trick !

How does "Kodetricks" work?

We at kodeplay like to share knowledge. With Kodetricks, even you can join us. All you need to do is post a programming related trick if you have one or rate a trick if you like someone else's.



Find us on

Technology

Contact Us