Today, We want to share with you PHP Tutorial.In this post we will show you PHP Tutorials For Beginners Step By Step With Example, hear for PHP Tutorials – An Ultimate Guide for Beginners we will give you demo and example for implement.In this post, we will learn about PHP Tutorials for Beginners with an example.
PHP Tutorial
There are the Following The simple About Step-by-Step PHP Tutorials for Beginners Full Information With Example and source code.
As I will cover this Post with live Working example to develop PHP Programming Language – PHP Tutorial for Beginners, so the PHP :How To Start Programming is used for this example is following below.
Basic PHP Tutorials – The PHP Hypertext Preprocessor (PHP) is a simple programming language that allows all the fresh & new web developers to make a dynamic Data content that interacts with MySQL & MySQLi databases.
Characteristics of PHP
- Simplicity
- Efficiency
- Security
- Flexibility
- Familiarity
Hello World using PHP
<html> <head> <title>Simple PHP Hello World Example</title> </head> <body> <?php echo "Hello, World!";?> </body> </html>
PHP Tutorials Index
php array length
array length php Example:PHP count() Function
<?php $players=array("Virat","Rohit","Ganguli"); echo count($players); ?>
PHP array printing using a loop
$length = count($players); for ($i = 0; $i < $length; $i++) { print $players[$i]; }
How to get Array length in PHP?
php count vs sizeof
using count
$player_nums = array (5,7,9,11,13); echo "The size of players = ", count($player_nums);
using sizeof
$player_nums = array (5,7,9,11,13); echo "The size of players = ", sizeof($player_nums);
PHP Date & Time Function with Example
php timestamp
Getting a list of available time zone identifiers
<?php $timezone_list = DateTimeZone::listIdentifiers(); foreach($timezone_list as $key => $list){ echo $list . "<br/>"; } ?>
PHP set Timezone Programmatically
<?php date_default_timezone_set ( string $timezone_identifier ); ?>
changes/updates the default time zone to Asia/Calcutta and displays the time again.
<?php echo "PHP :- The time in " . date_default_timezone_get() . " is " . date("H:i:s"); date_default_timezone_set("Asia/Calcutta"); echo "The time in " . date_default_timezone_get() . " is " . date("H:i:s"); ?>
Getting Current Timestamp in PHP
using time()
<?php $active_new_time_stamp = time(); echo $active_new_time_stamp; ?>
using strtotime()
<?php $active_new_time_stamp = strtotime("now"); echo $active_new_time_stamp; ?>
using mktime()
<?php $active_new_time_stamp_by_mktime = mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y")); echo $active_new_time_stamp_by_mktime; ?>
using microtime()
<?php $active_new_time_stamp_string = microtime(); echo $active_new_time_stamp_string; $active_new_time_stamp_float = microtime(TRUE); echo $active_new_time_stamp_float; ?>
using Date
<?php $active_new_time_stamp_fndate = date("U"); echo $active_new_time_stamp_fndate; ?>
PHP Date/Time to Timestamp Conversion
<?php $date_from_timestamp = date("d-m-Y",$active_new_time_stamp); echo "Your Formatted date from timestamp:" . $date_from_timestamp; ?>
php variable scope
Local variable
<?php function local_var() { $parms = 98; //local variable echo "Local variable declared inside the function is: ". $parms; } local_var(); ?>
Global variable
<?php $god_name = "Krishna Vashudev"; //Global Variable function global_var() { global $god_name; echo "Variable inside the function: ". $god_name; echo "</br>"; } global_var(); echo "Variable outside the function: ". $god_name; ?>
Static variable
<?php function static_var() { static $parms1 = 3; //static variable $parms2 = 6; //Non-static variable //increment in non-static variable $parms1++; //increment in static variable $parms2++; echo "Static: " .$parms1 ."</br>"; echo "Non-static: " .$parms2 ."</br>"; } //first function call static_var(); //second function call static_var(); ?>
Function parameters (local scope)
<?php function getBawlers() { $player = 'bhuvenswar'; $getBats = function () { // $player cannot be accessed inside here $batsmen = 'virat'; }; // $batsmen cannot be accessed outside here } ?>
php get ip address
php get ip, get ip php Examples
How to Get IP Address of User in PHP?
function retriveUserIpAddr(){ if(!empty($_SERVER['HTTP_CLIENT_IP'])){ $ip_address = $_SERVER['HTTP_CLIENT_IP']; }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; }else{ $ip_address = $_SERVER['REMOTE_ADDR']; } return $ip_address; } echo 'Fetch User Real IP - '.retriveUserIpAddr();
Get the Visitors(Users) IP Address
<?php $ip_Address = $_SERVER['REMOTE_ADDR']; echo "Here is thereal IP Address of Visitors : ".$ip_Address; ?>
Get the IP address of the website
<?php $pakainfoipAddress = gethostbyname("www.pakainfo.com"); echo "Here is the IP Address of pakainfo : ".$pakainfoipAddress; echo "</br>"; $infinityknow_ip_address = gethostbyname("www.infinityknow.com"); echo "Here is the IP Address of infinityknow : ".$infinityknow_ip_address; ?>
PHP json encode
PHP JSON Encode and Decode Examples
PHP json_encode()
<?php $players_name = array("virat","dhoni","sachin"); //returns ["virat","dhoni","sachin"] $player_json_format = json_encode($players_name); print "JSON Formatted String:" . $player_json_format; //returns {"0":"virat","1":"dhoni","2":"sachin"} $obj_json_format = json_encode($players_name, JSON_FORCE_OBJECT); print "<hr/><hr/>JSON Object:" . $obj_json_format; //returns [ "virat", "dhoni", "sachin" ] $strJsonFormat_with_space = json_encode($players_name, JSON_PRETTY_PRINT); print "<hr/><hr/>JSON Formatted String with white space:" . $strJsonFormat_with_space; ?>
Example: json_decode()
$str_json_array_decoded = json_decode($player_json_format); print "<hr/><hr/>Resultant decoded array from JSON array:<hr/>"; print "<pre>"; print_r($str_json_array_decoded); print "</pre>"; $str_objJson_decoded = json_decode($obj_json_format); print "<hr/><hr/>Resultant decoded object data from JSON object:<hr/>"; print "<pre>"; print_r($str_objJson_decoded); print "</pre>"; $str_jsonAry_decoded = json_decode($obj_json_format,true); print "<hr/><hr/>Resultant decoded array data from JSON object:<hr/>"; print "<pre>"; print_r($str_jsonAry_decoded); print "</pre>";
encapsulation in php
Encapsulation in PHP
<?php class member { public $name; public $age; function __construct($n, $a) { $this->name=$n; $this->age=$a; } public function setAge($ag) { $this->ag=$ag; } public function display() { echo "welcome ".$this->name."<br/>"; return $this->age-$this->ag; } } $member=new member("Sejal",35); $member->setAge(25); echo "You are ".$member->display()." years old"; ?>
<?php class BANKATM { private $memberid; private $atmpin; public function PinChange($memberid,$atmpin) { ---------added your code----- } public function CheckBalance($memberid,$atmpin){ ---------added your code----- } public function miniStatement($memberid) { ---------added your code----- } } $obj = new BANKATM(); $obj ->CheckBalance(89985356851234,1**3); ?>
Web Programming Tutorials Example with Demo
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about How to learn PHP: a 15 days program for beginners?.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.
Related FAQ
Here are some more FAQ related to this Article: