Remove Leading Zeros Using PHP

It is actually two way to remove unnecessary Zeros

(1) ltrim()

Example : echo ltrim(”001″,”0″);
Result : 1

(2) intval()

Example : echo intval(”001″);
Result : 1

Conversion of MySQL Timestamp and DateTime to Unix based TimeStamp

About MySQL TimeStamp

* The Prior version of MySQL v4.1 the timestamp was formatted as like YYYYMMDDHHMMSS”
* since after MySQL v4.1 timestamp and datetime data types are formatted “YYYY-MM-DD HH:MM:SS”.

About Unix Based TimeStamp

* It is differ from MySQL. Unix’s timestamp is a integer value of seconds since January 1, 1970.


How To - Convert

(1) Using MySQL

* you can use Unix_Timestamp() function.
* Example:
SELECT Unix_Timestamp(Created) FROM CreatedItem;

(2) Using PHP
* you can use strtotime() function.
* Example:
$unixTimeStamp = strtotime($createdTimestamp);

stdClass in php

stdClass is php's generic empty class or say default PHP object which has no predefined members, kind of like Object in Java
you cannot define a class named stdClass in your PHP code. Useful for anonymous objects, dynamic properties,

StdClass object creation. Something like this would be great:

$foo = {”bar”: “baz”, “bam”: “boom”};

so you end up doing something like this:

$foo = new StdClass;
$foo->bar = “baz”;
$foo->bam = “boom”;

but you don’t have to. Using PHP’s casting operator you can create the object in one line:
$foo = (object) array(”bar” => “baz”, “bam” => “boom”);

usage is casting an array to an object which takes each value in the array and adds it as a member variable with the name based on the key
in the array.

Here’s an example below that converts an array to an object below. This method is called Type Casting

'Divyesh',
'lastname' => 'Karelia'
);

$p = (object) $person;
echo $p->firstname; // Will print 'Divyesh'
?>


Here’s an example below that converts a multi-dimensional array to an object. This is accomplished through recursion.

02.function arrayToObject($array) {
03. if(!is_array($array)) {
04. return $array;
05. }
06.
07. $object = new stdClass();
08. if (is_array($array) && count($array) > 0) {
09. foreach ($array as $name=>$value) {
10. $name = strtolower(trim($name));
11. if (!empty($name)) {
12. $object->$name = arrayToObject($value);
13. }
14. }
15. return $object;
16. }
17. else {
18. return FALSE;
19. }
20.}
21.?>


array('name' => 'Divyesh'),
'last' => array('name' => 'Karelia')
'
);

$p = arrayToObject($person);
?>

first->name; // Will print 'Divyesh'
?>

Drupal .module extension treate as php file (syntax color) in Eclipse

Recently I started to work in Drupal. I came across strange little problem with Drupal’s module development, syntax coloring and general PHP support when it comes to files with extension different than .php or .phtml. Lucky for me,

Eclipse comes with a nice solution for these kind of situations.

All you need to do in order for Eclipse to treat .module extensions as .php is to go to

Window Menu > Preferences > General > Content Types > (Select) Text > PHP Content TYpe from the Content types area, then below under

File Associations click on Add button and write down any extension you wish. In Drupal CMS case, write down “.module”.

Now you should be able to work with .module files as with all other .php files.

Top 10 Drupal Modules

Every CMS system should have a rich variety of extensions and add-ons, and so does Drupal have. In Paul Koura (webpodge.com) has made a top 10 list of those modules that he finds most valuable for Drupal.

His list is as shown below, in priority order:

  1. Content Construction Kit

  2. Views

  3. Tagadelic

  4. Path and Pathauto

  5. Organic Groups

  6. Buddylist

  7. Privatemsg

  8. Guestbook

  9. Logintoboggan

  10. Service Links

You can read Paul Koura's blog post including comments about each module here:
http://webpodge.com/2007/02/22/top-10-drupal-modules/

Easy to under standing File Upload in PHP

see simple tutorial how to upload file in php

http://www.sebastiansulinski.co.uk/web_design_tutorials/php/php_file_upload.php

change the PHP Max Upload file size

Last 2 yeara ago, I made a php-upload code for www.blemo.com, this site is specialy for mp3 sound and image gallary, regardings to this functionality user can upload multiple mp3 sound file at a time. that time I did not know about file uplode limit and it's setting
I tried much but some of file uploded and some of not for multipul file upload.

search some solution for that.

Most of the web servers are configured such a way that a user can only upload the maximum file size of 2MB.anything more will yield an error 500 due to a timeout. So there might be the problem for the people who wants to upload the .media file of size around 15MB. But, you can increse the maximum upload file size limit describe below.

There are two ways (that I know of) to change the php upload limit.

(1) changes in php.ini

The first is done by editing the php.ini file. This is normally the case if you have your own dedicated or virtual server. There may be multiple php.ini files throughout your system. The main one is typically found in /etc/php.ini which would govern all PHP. scripts.Furthermore you can include php.ini file in each folder that you wish to apply different settings to. In any case the, below are the fields you want to change.

upload_max_filesize = 10M ;
post_max_size = 20M ;


(2) by .htaccess

An alternative is to using the php.ini file is to use .htaccess. By just placing a.htaccess file in your root folder. the following directive would be placed in .htaccess file

RewriteEngine On
php_value post_max_size 20M
php_value upload_max_filesize 10M
php_value max_execution_time 6000000


Remember that : Choose your values carefully, know your audience and monitor the number of users. Always test/plan for worst case scenarios; 500 users uploading 10mb at the same time = 5,000mb bandwidth. This could easily annoy your web host provider.

If you are on windows with IIS server .htaccess file will not work for you,You should update these settings in php.ini file.