PHP Date and Time format with examples and descriptions

Date Examples:

OutputFormatExample
15/02/19d/m/ydate( ‘d/m/y’ )
15-Feb-2019d-M-Ydate( ‘d-M-Y’ )
15 February 2019d F Ydate( ‘d F Y’ )
15th February 2019dS F Ydate( ‘dS F Y’ )
Feb, 15th 2019M, dS Ydate( ‘M, dS Y’ )

Time 12 hrs Examples:

OutputFormatExample
05:36 pmh:i adate( ‘h:i a’ )
05:36 PMh:i Adate( ‘h:i A’ )
05:36:18 pmh:i:s adate( ‘h:i:s a’ )
05:36:18 PMh:i:s Adate( ‘h:i:s A’ )

Time 24 hrs Examples:

OutputFormatExample
17:36 pmH:i adate( ‘H:i a’ )
17:36 PMH:i Adate( ‘H:i A’ )
17:36:18 pmH:i:s adate( ‘H:i:s a’ )
17:36:18 PMH:i:s Adate( ‘H:i:s A’ )

Date & Time Examples:

OutputFormatExample
15-02-2019 05:36:18 pmd-m-Y h:i:s adate( ‘d-m-Y h:i:s a’ )
15-Feb-2019 05:36:18 pmd-M-Y h:i:s adate( ‘d-M-Y h:i:s a’ )
15 February 2019 05:36 pmd F Y h:i adate( ‘d F Y h:i a’ )

All format with example and description:

FormatExampleDescription
d15d – The day of the month (from 01 to 31)
DFriD – A textual representation of a day (three letters)
j15j – The day of the month without leading zeros (1 to 31)
lFridayl (lowercase ‘L’) – A full textual representation of a day
N5N – The ISO-8601 numeric representation of a day (1 for Monday, 7 for Sunday)
SthS – The English ordinal suffix for the day of the month (2 characters st, nd, rd or th. Works well with j)
w5w – A numeric representation of the day (0 for Sunday, 6 for Saturday)
z45z – The day of the year (from 0 through 365)
W07W – The ISO-8601 week number of year (weeks starting on Monday)
FFebruaryF – A full textual representation of a month (January through December)
m02m – A numeric representation of a month (from 01 to 12)
MFebM – A short textual representation of a month (three letters)
n2n – A numeric representation of a month, without leading zeros (1 to 12)
t28t – The number of days in the given month
L0L – Whether it’s a leap year (1 if it is a leap year, 0 otherwise)
o2019o – The ISO-8601 year number
Y2019Y – A four digit representation of a year
y19y – A two digit representation of a year
apma – Lowercase am or pm
APMA – Uppercase AM or PM
B775B – Swatch Internet time (000 to 999)
g5g – 12-hour format of an hour (1 to 12)
G17G – 24-hour format of an hour (0 to 23)
h05h – 12-hour format of an hour (01 to 12)
H17H – 24-hour format of an hour (00 to 23)
i36i – Minutes with leading zeros (00 to 59)
s18s – Seconds, with leading zeros (00 to 59)
u000000u – Microseconds (added in PHP 5.2.2)
eUTCe – The timezone identifier (Examples: UTC, GMT, Atlantic/Azores)
I0I (capital i) – Whether the date is in daylights savings time (1 if Daylight Savings Time, 0 otherwise)
O+0000O – Difference to Greenwich time (GMT) in hours (Example: +0100)
P+00:00P – Difference to Greenwich time (GMT) in hours:minutes (added in PHP 5.1.3)
TUTCT – Timezone abbreviations (Examples: EST, MDT)
Z0Z – Timezone offset in seconds. The offset for timezones west of UTC is negative (-43200 to 50400)
c2019-02-15T17:36:18+00:00c – The ISO-8601 date (e.g. 2013-05-05T16:34:42+00:00)
rFri, 15 Feb 2019 17:36:18 +0000r – The RFC 2822 formatted date (e.g. Fri, 12 Apr 2013 12:01:05 +0200)
U1550252178U – The seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)

Profiling with Blackfire for WordPress

Setup Blackfire profiling tool on your local machine ( I’m installing it on Windows ). Profiling help developer to analyse there coding performance. Find unwanted calls / memory issues and helps to optimize all the possible issues.

# Setup Blackfire Environment

Follow below 10 steps to setup Blackfire on Windows system. For other system setup goto https://blackfire.io/


Step 1) Download Binary Files

Download 32 Bit Binary file
Download 64 Bit Binary file

For latest binary files goto – Blackfire Installation


Step 2) Create Blackfire directory in your system.

I’m creating it like C:\Program Files\Blackfire.


Step 3) Set Windows PATH environment variable.

You can set it though Command Prompt ( CMD ) OR though windows Edit System Environment.
I’m using command prompt.

So, I follow below steps:

- Add though 'Command Prompt ( CMD )'
- Open Command Prompt by pressing `( Windows + R )` key. Or Goto start menu and search `command prompt`.
- Add command <strong>set PATH=%PATH%;C:\Program Files\Blackfire</strong> - <strong>NOTE:</strong> Add location where you extract the Blackfire binary files.

Add below command and confirm the system path is perfectly set.

echo %path%

Step 4) Create ‘agent.ini’ like ‘C:\Program Files\Blackfire\agent.ini’. And add below code.

Note: Please add your MY_SERVER_ID & MY_SERVER_TOKEN which you get it after login / register to http://blackfire.io

Or

Avoid below step. Goto Blackfire Configure

Here, Blackfire auto generate your agent.ini with your MY_SERVER_ID & MY_SERVER_TOKEN.

[blackfire]
;
; setting: ca-cert
; desc   : Sets the PEM encoded certificates
; default:
ca-cert=

;
; setting: collector
; desc   : Sets the URL of Blackfire's data collector
; default: https://blackfire.io
collector=https://blackfire.io/

;
; setting: log-file
; desc   : Sets the path of the log file. Use stderr to log to stderr
; default: stderr
log-file=stderr

;
; setting: log-level
; desc   : log verbosity level (4: debug, 3: info, 2: warning, 1: error)
; default: 1
log-level=1

;
; setting: server-id
; desc   : Sets the server id used to authenticate with Blackfire API
; default:
server-id=[MY_SERVER_ID]

;
; setting: server-token
; desc   : Sets the server token used to authenticate with Blackfire API. It is unsafe to set this from the command line
; default:
server-token=[MY_SERVER_TOKEN]

;
; setting: socket
; desc   : Sets the socket the agent should read traces from. Possible value can be a unix socket or a TCP address
; default: unix:///var/run/blackfire/agent.sock on Linux, unix:///usr/local/var/run/blackfire-agent.sock on MacOSX, and tcp://127.0.0.1:8307 on Windows.
socket=unix:///var/run/blackfire/agent.sock

;
; setting: spec
; desc   : Sets the path to the json specifications file
; default:
spec=

Step 5) Goto ‘Command Prompt’ and add below commands:

cd C:
cd C:\Program Files\Blackfire\
blackfire-agent -register

Add your Server Id & Server Token which you get from http://blackfire.io

blackfire config

Add your Server Id & Server Token which you get from http://blackfire.io


Step 6) Download PHP ‘.dll’ file for blackfire and rename with ‘php_blackfire.dll’.
You can download it by your system & PHP version.

E.g.
Download 32 Bit & PHP 7
Download 32 Bit & PHP 7

Or

Download appropriate PHP ‘.dll’ from Blackfire Get Dll


Step 7) Goto PHP extensions directory. I have it in ‘C:\xampp\php\ext\’. And move downloaded ‘php_blackfire.dll’ within it.


Step 8) Open ‘php.ini’ file and add below code:

Note: If you have ‘XDebug’ or ‘XHProf’ then disable these.

[blackfire]
extension=blackfire.so
; On Windows use the following configuration:
extension=php_blackfire.dll


; Sets the socket where the agent is listening.
; Possible value can be a unix socket or a TCP address.
; Defaults to unix:///var/run/blackfire/agent.sock on Linux,
; unix:///usr/local/var/run/blackfire-agent.sock on MacOSX,
; and to tcp://127.0.0.1:8307 on Windows.
;blackfire.agent_socket = unix:///var/run/blackfire/agent.sock

blackfire.agent_timeout = 0.25

; Log verbosity level (4: debug, 3: info, 2: warning, 1: error)
;blackfire.log_level = 1

; Log file (STDERR by default)
;blackfire.log_file = /tmp/blackfire.log

;blackfire.server_id =

;blackfire.server_token =

Step 9) Open ‘.htaccess’ file in which local site you want to test the blackfire and add below code:

Note: Add your Server ID & Server Token.

    php_admin_value blackfire.server_id "[MY_SERVER_ID]"
    php_admin_value blackfire.server_token "[MY_SERVER_TOKEN]"

Step 10) Download blackfire chrome extension from Download Blackfire Chrome


Step 11) Goto – ‘C:\Program Files\Blackfire’ and execute blackfire-agent.exe.

It open the black window. KEEP THIS WINDOW AS IT IS. Minimize it. ( DON’T CLOSE IT ).

Its done. Lets test it.

  • Goto the local website in which ‘.htaccess’ you added blackfire.

  • I have http://localhost/dev.themes/ – Click on installed chrome extension icon from top right. – And click on ‘Profile’ button.


# Analyse Profiling Result

Goto your Blackfire dashboard and analyse your blackfire profiling result. Click here for depth analyzing profiles

E.g.

How to read .xml file using PHP?

Yes, it is possible by using “simplexml_load_file()” function.

In this tutorial we read “all_products.xml” using index.php file.

Step-1: Create “all_products.xml” by copy and paste this code

 


1
<frame_style>Full Rimmed
../images/products/glasses/unisex/main_thumbnail/1.jpg
150 Black

2
<frame_style>Full Rimmed
../images/products/glasses/unisex/main_thumbnail/3.jpg
120 Black

 

How to use PHP for Developing Dynamic Website?

[ NOTE: This article just show concept of how to use php for developing dynamic Websites.]

 [ NOTE: If you want to know how php execute practically, Please visit our PRACTICLE tutorial “How to execute PHP files on LOCALHOST using WAMP, MAMP or XAMPP?”  It shows you how to execute php files on LOCAL computer. It also show which software’s and tools used for doing it. ]

Continue reading “How to use PHP for Developing Dynamic Website?”

How to execute PHP files on LOCALHOST using WAMP, MAMP or XAMPP?

In this tutorial I will show you how to Execute PHP files using WAMP.

Note: Execution procedure of PHP files on WAMP, MAMP and XAMPP are similler.

Continue reading “How to execute PHP files on LOCALHOST using WAMP, MAMP or XAMPP?”