Home » PHP Tutorial

PHP Tutorial

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

Sr.No. Topics
1 PHP Introduction For Beginners
2 PHP IDE
3 PHP Software Requirement
4 PHP WAMP Installation
5 PHP XAMPP Installation
6 PHP Syntax
7 PHP Comments
8 PHP Variables
9 PHP $ and $$ Variables
10 PHP Super global variables
11 How to swap two numbers in PHP
12 PHP Constant
13 PHP:Magic Constant
14 echo and print in PHP
15 PHP Data Types
16 PHP Form
17 GET Method
18 POST Method
19 Form action
20 PHP Display result in Textbox
21 Multiple submit buttons php different actions
22 Add two textbox values and display the result in third textbox
23 PHP Operators
24 PHP Arithmetic Operators
25 PHP Assignment Operators
26 PHP Comparative Operators
27 PHP Logical Operators
28 PHP Operators Precedence
29 PHP Conditional Statement
30 PHP if Statement
31 PHP if-else Statement
32 PHP if elseif else Statement
33 PHP Switch Statement
34 PHP calculator
35 Profit and Loss
36 What is Loop
37 PHP For Loop
38 Print star pattern in PHP
39 Create table using for loop in PHP
40 PHP While Loop
41 PHP Do While Loop
42 PHP Foreach Loop
43 PHP String
44 PHP Numeric Functions
45 PHP Tutorial PDF For Beginners
46 PHP isset function
Read Also:  How to Use Time Sleep in Python Script?

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.

Read Also:  laravel middleware check custom header for REST API

<?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

Read Also:  PHP Variable Scope Global Static & Local

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:

  1. Read Also:  Google Like Autosuggest Search Using PHP Ajax
  2. Read Also:  react open link in new tab
  3. Read Also:  Multiselect dropdown with checkboxes demo code in php
  4. Read Also:  Laravel Get Real client IP address from request
  5. Read Also:  AngularJS Remove Last Comma from String
  6. Read Also:  Laravel 6 Inner Join Query Example - MySQL
  7. Read Also:  Laravel 6 csrf tokens in ajax calls
  8. Read Also:  order by multiple columns(fields) laravel query builder
  9. Read Also:  vuejs Smooth Scroll to Top
  10. Read Also:  JavaScript Image Thumbnails Preview Gallery

Leave a Comment

Your email address will not be published. Required fields are marked *