Showing posts with label Learn PHP Online. Show all posts
Showing posts with label Learn PHP Online. Show all posts

Thursday, October 8, 2009

How do I get local date & time with the PHP date & time function?

PHP's int time() function returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). The string date ( string format [, int timestamp] ) returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given. In other words, timestamp is optional and defaults to the value of time(). If you want to have a manual date timezone convertion see the code below.

Example

<?php 
    $gmt_timezone_offset = +8;
    $time = time();
    $my_gmt_timezone = $time + ($gmt_timezone_offset * 60 * 60);
    echo date("Y-m-d H:i:s", $my_gmt_timezone);
?>

Or Simply, you can do this:
<?php 
    // put this code at the very top of your file
    ini_set('date.timezone', "Asia/Taipei");
    ...
?>

Or you can modify php.ini.

...
date.timezone = "Asia/Taipei"
...

Or you can modify .htaccess
...
php_value date.timezone Asia/Taipei
# or
php_value date.timezone UTC
...

The following table indicates each timezone and its location. Below are the list of timezone reference:

http://php.net/manual/en/timezones.php

OR

Time Zone Location
UM12 (UTC - 12:00) Enitwetok, Kwajalien
UM11 (UTC - 11:00) Nome, Midway Island, Samoa
UM10 (UTC - 10:00) Hawaii
UM9 (UTC - 9:00) Alaska
UM8 (UTC - 8:00) Pacific Time
UM7 (UTC - 7:00) Mountain Time
UM6 (UTC - 6:00) Central Time, Mexico City
UM5 (UTC - 5:00) Eastern Time, Bogota, Lima, Quito
UM4 (UTC - 4:00) Atlantic Time, Caracas, La Paz
UM25 (UTC - 3:30) Newfoundland
UM3 (UTC - 3:00) Brazil, Buenos Aires, Georgetown, Falkland
Is.
UM2 (UTC - 2:00) Mid-Atlantic, Ascention Is., St Helena
UM1 (UTC - 1:00) Azores, Cape Verde Islands
UTC (UTC) Casablanca, Dublin, Edinburgh, London, Lisbon, Monrovia
UP1 (UTC + 1:00) Berlin, Brussels, Copenhagen, Madrid, Paris,
Rome
UP2 (UTC + 2:00) Kaliningrad, South Africa, Warsaw
UP3 (UTC + 3:00) Baghdad, Riyadh, Moscow, Nairobi
UP25 (UTC + 3:30) Tehran
UP4 (UTC + 4:00) Adu Dhabi, Baku, Muscat, Tbilisi
UP35 (UTC + 4:30) Kabul
UP5 (UTC + 5:00) Islamabad, Karachi, Tashkent
UP45 (UTC + 5:30) Bombay, Calcutta, Madras, New Delhi
UP6 (UTC + 6:00) Almaty, Colomba, Dhaka
UP7 (UTC + 7:00) Bangkok, Hanoi, Jakarta
UP8 (UTC + 8:00) Beijing, Hong Kong, Perth, Singapore, Taipei
UP9 (UTC + 9:00) Osaka, Sapporo, Seoul, Tokyo, Yakutsk
UP85 (UTC + 9:30) Adelaide, Darwin
UP10 (UTC + 10:00) Melbourne, Papua New Guinea, Sydney, Vladivostok
UP11 (UTC + 11:00) Magadan, New Caledonia, Solomon Islands
UP12 (UTC + 12:00) Auckland, Wellington, Fiji, Marshall Island

Tuesday, September 29, 2009

Introduction - Learn PHP

Learn PHP


Before we start, we have to know first more about PHP. PHP stands for PHP Hypertext Preprocessor is a server-side scripting language, and server-sidescripts are special commands you must place in Web pages. Those commands are processed before the pages are sent from your Server to the Web browser of your visitor. A typical PHP files will content commads to be executed in the server in addition to the usual mixture of text and HTML (Hypertext Markup Language) tags.

What Can You Do with PHP?


Anything. PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies. But PHP can do much more.

There are three main areas where PHP scripts are used.

Server-side scripting. This is the most traditional and main target field for PHP. You need three things to make this work. The PHP parser (CGI or server module), a web server and a web browser. You need to run the web server, with a connected PHP installation. You can access the PHP program output with a web browser, viewing the PHP page through the server. All these can run on your home machine if you are just experimenting with PHP programming. See the installation instructions section for more information.


Command line scripting. You can make a PHP script to run it without any server or browser. You only need the PHP parser to use it this way. This type of usage is ideal for scripts regularly executed using cron (on *nix or Linux) or Task Scheduler (on Windows). These scripts can also be used for simple text processing tasks. See the section about Command line usage of PHP for more information.

Writing desktop applications. PHP is probably not the very best language to create a desktop application with a graphical user interface, but if you know PHP very well, and would like to use some advanced PHP features in your client-side applications you can also use PHP-GTK to write such programs. You also have the ability to write cross-platform applications this way. PHP-GTK is an extension to PHP, not available in the main distribution. If you are interested in PHP-GTK, visit » its own website.

PHP can be used on all major operating systems, including Linux, many Unix variants (including HP-UX, Solaris and OpenBSD), Microsoft Windows, Mac OS X, RISC OS, and probably others. PHP has also support for most of the web servers today. This includes Apache, Microsoft Internet Information Server, Personal Web Server, Netscape and iPlanet servers, Oreilly Website Pro server, Caudium, Xitami, OmniHTTPd, and many others. For the majority of the servers, PHP has a module, for the others supporting the CGI standard, PHP can work as a CGI processor.

So with PHP, you have the freedom of choosing an operating system and a web server. Furthermore, you also have the choice of using procedural programming or object oriented programming, or a mixture of them. Although not every standard OOP feature is implemented in PHP 4, many code libraries and large applications (including the PEAR library) are written only using OOP code. PHP 5 fixes the OOP related weaknesses of PHP 4, and introduces a complete object model.

With PHP you are not limited to output HTML. PHP's abilities includes outputting images, PDF files and even Flash movies (using libswf and Ming) generated on the fly. You can also output easily any text, such as XHTML and any other XML file. PHP can autogenerate these files, and save them in the file system, instead of printing it out, forming a server-side cache for your dynamic content.

One of the strongest and most significant features in PHP is its support for a wide range of databases. Writing a database-enabled web page is incredibly simple. The following databases are currently supported:







* Adabas D
* dBase
* Empress
* FilePro (read-only)
* Hyperwave
* IBM DB2
* Informix
* Ingres
* InterBase
* FrontBase
* mSQL
* Direct MS-SQL
* MySQL
* ODBC
* Oracle (OCI7 and OCI8)
* Ovrimos
* PostgreSQL
* SQLite
* Solid
* Sybase
* Velocis
* Unix dbm
We also have a database abstraction extension (named PDO) allowing you to transparently use any database supported by that extension. Additionally PHP supports ODBC, the Open Database Connection standard, so you can connect to any other database supporting this world standard.

PHP also has support for talking to other services using protocols such as LDAP, IMAP, SNMP, NNTP, POP3, HTTP, COM (on Windows) and countless others. You can also open raw network sockets and interact using any other protocol. PHP has support for the WDDX complex data exchange between virtually all Web programming languages. Talking about interconnection, PHP has support for instantiation of Java objects and using them transparently as PHP objects. You can also use our CORBA extension to access remote objects.

PHP has extremely useful text processing features, from the POSIX Extended or Perl regular expressions to parsing XML documents. For parsing and accessing XML documents, PHP 4 supports the SAX and DOM standards, and you can also use the XSLT extension to transform XML documents. PHP 5 standardizes all the XML extensions on the solid base of libxml2 and extends the feature set adding SimpleXML and XMLReader support.

At last but not least, we have many other interesting extensions, the mnoGoSearch search engine functions, the IRC Gateway functions, many compression utilities (gzip, bz2, zip), calendar conversion, translation...

As you can see this page is not enough to list all the features and benefits PHP can offer. Read on in the sections about installing PHP, and see the function reference part for explanation of the extensions mentioned here.

What you should know

Before starting this tutorial it is important that you have a basic understanding and experience in the following:

* HTML - Know the syntax and especially HTML Forms.
* Basic programming knowledge - This isn't required, but if you have any traditional programming experience it will make learning PHP a great deal easier.

Source: http://us.php.net/manual/en/intro-whatcando.php