Breaking

PHP Scripting Tutorial For Beginner

PHP is a popular general-purpose scripting language that is especially suited to web development. Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world. 


Before starting the tutorial you need to install few tools

  1. Install xampp or wamp. If you are using windows you need to put all php file in C:\\localdrive\xampp\htdocs or find htdocs folder and create a project folder and create a index.php file that will be default main file of the project. Once you made index.php write something there and open your xampp control panel and start apache and mysql then open your borwser and navigate to http://localhost. 
  2. Install atom, visual studio code or any of your text editor and open your project folder within your editor and start writing code.

index.php

<?php

// String
$playerName = "Neymar JR";



// INTEGER
$playerNumber = 10;
// DOUBLE
$playingTime = 61.34;
// BOOLEAN
$psgOwnUCL = false;
// NULL
$plyer_info = null;
$playerClub = 'PSG';


// print or echo


echo $playerNumber;
echo "<hr>";
echo $playerName;
echo "<hr>";
echo $playingTime ,  $playerClub;
echo "<hr>";
echo "Player Name " . $playerName . " Player Number " . $playerNumber;




echo "<hr>";
echo "<hr>";
print($playerName);
echo "<hr>";
print "Player Name " . $playerName . " Player Number " . $playerNumber;
print "<h2>This is header 2</h2>";
 ?>



On the browser use url http://localhost/tut-3.php

tut-3.php

<?php
/*
All variables in PHP are denoted with a leading dollar sign ($).

The value of a variable is the value of its most recent assignment.

Variables are assigned with the = operator, with the variable on the left-hand side and the expression to be evaluated on the right.

Variables can, but do not need, to be declared before assignment.

*/
// String
$playerName = "Neymar JR";


/*

PHP has a total of eight data types which we use to construct our variables −

Integers − are whole numbers, without a decimal point, like 4195.

Doubles − are floating-point numbers, like 3.14159 or 49.1.

Booleans − have only two possible values either true or false.

NULL − is a special type that only has one value: NULL.

Strings − are sequences of characters, like 'PHP supports string operations.'

Arrays − are named and indexed collections of other values.

Objects − are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class.

Resources − are special variables that hold references to resources external to PHP (such as database connections).
*/


// INTEGER
$playerNumber = 10;
// DOUBLE
$playingTime = 61.34;
// BOOLEAN
$psgOwnUCL = false;
// NULL
$plyer_info = null;
$playerClub = 'PSG';




 ?>



On the browser use url http://localhost/tut-4.php

tut-4.php

<?php

// String
$playerName = "Neymar JR";



// INTEGER
$playerNumber = 10;
// DOUBLE
$playingTime = 61.34;
// BOOLEAN
$psgOwnUCL = false;
// NULL
$plyer_info = null;
$playerClub = 'PSG';


// print or echo


echo $playerNumber;
echo "<hr>";
echo $playerName;
echo "<hr>";
echo $playingTime ,  $playerClub;
echo "<hr>";
echo "Player Name " . $playerName . " Player Number " . $playerNumber;




echo "<hr>";
echo "<hr>";
print($playerName);
echo "<hr>";
print "Player Name " . $playerName . " Player Number " . $playerNumber;
print "<h2>This is header 2</h2>";
 ?>



On the browser use url http://localhost/tut-5.php

tut-5.php

<?php

// String
$playerName = "Neymar JR";


echo "this is multiline
code
";


echo "this will  no\t break $playerName";
echo "<br >";


// ENCODE STRING
$encodedString = convert_uuencode("Neymar JR");
// DECODE STRING
$decodedString = convert_uudecode($encodedString);

echo "<hr >";


$exampleSplit = "This-is-to-be-split";
$makeArray =  explode('-', $exampleSplit);

var_dump($makeArray);


echo "<hr >";


$exampleSubString = "This is example of substring";
$ess = substr($exampleSubString, 5);
echo $ess;




 ?>





1 comment:

  1. The PHP programming language has been used by people for over two decades and it is a powerful and reliable solution, gaining an army of admirers and supporters. However, with time this coding language is losing its users and popularity due to the optimized counterparts.

    ReplyDelete

Powered by Blogger.