PHP While loop do over and over tasks as long as the specified condition is true.
Syntax:
while (condition){
// to do
}
This blog supports beginners to get deep knowledge about programming in HTML, CSS, JavaScript, php, asp and other Web technologies and VB, VB.net, Java,step by step from the beginning. All the programming Concepts discuss with simple examples for the readability. Try out daily uploaded lessons to be a Programmer.
PHP - Switch Statement
Switch statement uses to perform different actions based on the different conditions of same variable at once. It takes one variable as an input and then check different conditions setup for switch statement. It acts like a set of if statements define for a variable.
Syntax:
switch (<variable>){
case <label 1>:
{code to be executed if the variable is label 1};
break;
case <label 2>:
{code to be executed if the variable is label 2};
break;
default:
{code to be executed if the variable is not equal to above labels};
break;
}
PHP - Post & Pre Increment & Decrement
This is a quite shorter way to add 1 to or subtract 1 from a variable.
Increment Operator
"++" uses to increase 1
Decrement Operator
"--" uses to decrease 1
Ex:
$no1 = 5;
$no1++; // This is equal to $no1 = $no1 + 1;
$no1--; // This is equal to $no1 = $no1 - 1;
Increment Operator
"++" uses to increase 1
Decrement Operator
"--" uses to decrease 1
Ex:
$no1 = 5;
$no1++; // This is equal to $no1 = $no1 + 1;
$no1--; // This is equal to $no1 = $no1 - 1;
- There is a difference when the increment operator uses before the variable and after the variable. If the operator uses before the variable then the value get after increasing the variable value. But put the increment operator after the variable then 1st it print the variable value and then increase the value by 1.
PHP - String Operators
The Period "." operator used to concatenate two or more strings together.
Ex:
<?php
$text1 = "Programming Languages";
$text2 = "for Beginners";
echo $text1 . " " . $text2; // Two string variables and a space join together
?>
Ex:
<?php
$text1 = "Programming Languages";
$text2 = "for Beginners";
echo $text1 . " " . $text2; // Two string variables and a space join together
?>
PHP - Heredoc String Creation
PHP traditional string creation method I've mentioned in earlier post. That method common to most of the programming languages. PHP introduces a more robust string string creation tool called Heredoc, it creates multi-line strings without using single or double quotes. This methods seems to be easy but it's too difficult and can be lead to arise errors if you do not properly code the string.
PHP - Conditional Statements
Conditional Statements are used to perform different actions based on the conditions.
In PHP, there are few conditional statements are used to do that.
In PHP, there are few conditional statements are used to do that.
- If Statement
Perform some actions if the condition is true. - If.. Else Statement
Perform some actions if the condition is true and another actions if its false. - If... ElseIf Statement
Perform some actions according to the conditions provided - Switch Statement
Blocks of codes can be executed
PHP - Constants
PHP Constant is an identifier for a value like a variable but it has some unique characteristics such as,
How to set a PHP Constant
There is a key word calling "define" uses to define the constants in PHP.
- Once you create a constant then you cant change it
- Once you create a constant then you cant undefined it
- Value cannot be changed during the script
- Constant Name starts with a Letter or underscore sign. There is no $ sign for constants.
How to set a PHP Constant
There is a key word calling "define" uses to define the constants in PHP.
PHP - How to read content of a file
PHP can read the content of files such as txt, doc, etc and can be displays it onto the web page as a HTML document.
Syntax:
readfile(<filename>);
Syntax:
readfile(<filename>);
JavaScript - Data Types
It is not necessary to define the data type when initializing the variables in Javascript. It automatically gets the data type of the variable according to the value stored in the variable. That is calling Dynamic Type Variables. Therefore Same variable can be used to store following kind of data in JavaScript
1. String
A set of characters can be stored by putting between the Double Quotes or Single Quote
Syntax:
var <variable name> = '<Value>' OR
var <variable name> = "<Value>"
Ex:
var student = "John"; // OR
var student = 'John';
var Relationship= "John's car"; // Can put single Quotes within Double Quotes
var car = 'John has "Toyota" car'; // Can put Double Quotes within Single Quotes
2. Number
Numbers in the can be written with or without decimal places.
var no1 = 50;
var no1 = 53.25;
1. String
A set of characters can be stored by putting between the Double Quotes or Single Quote
Syntax:
var <variable name> = '<Value>' OR
var <variable name> = "<Value>"
Ex:
var student = "John"; // OR
var student = 'John';
var Relationship= "John's car"; // Can put single Quotes within Double Quotes
var car = 'John has "Toyota" car'; // Can put Double Quotes within Single Quotes
2. Number
Numbers in the can be written with or without decimal places.
var no1 = 50;
var no1 = 53.25;
Javascript - Comments
We are using comments to make Javascript more readable and comments are not executed by JavaScript. That can be used to explain the coding. In JavaScript, there are two types of comments can be used,
01. Single Line Comments
Single Line Comments begins with 02 forward slashes and there is no ending, its
applicable to the whole line which it puts.
Syntax:
// <Comment>
Ex:
// This is a single line Comment
var no = 0; // This is Number type variable
02. Multi Line Comments
Multi Line Comments begins with a /* and ends with */.
Syntax:
/* <Comment> */
Ex:
/* This is a Multi line Comment
Purpose of this comment is explain
the code with more than one line */
Javascript - Variables
Javascript variables uses to contain information.
Syntax:
var <name> = <value>
Ex:
var No1 = 5;
var No2 = 10;
var total = No1 + No2;
Javascript Variable names;
1. must begins with a letter
2. can begins with $ or _
3. are case sensitive
How to define a Javascript Variable
1. Method 01
var carName = "Toyota"
2. Method 02
var carName;
carName = "Toyota";
Syntax:
var <name> = <value>
Ex:
var No1 = 5;
var No2 = 10;
var total = No1 + No2;
Javascript Variable names;
1. must begins with a letter
2. can begins with $ or _
3. are case sensitive
How to define a Javascript Variable
1. Method 01
var carName = "Toyota"
2. Method 02
var carName;
carName = "Toyota";
Web Programing for Beginners
Is this blog helpful for you? Can you recommend for someone?
I much appreciate your kind suggestions and comment to improve the contents & writing method of this blog. Because you are the actual reader of this site and strive to sharpen your web programming knowledge.
You may knowing further more about the discussed topics or have articles, links related to the topics please put it in your comment. Those comments more helpful others as well as me.
--
Best regards,
Priyal
PHP - Print the Processed data
It is the way to see the processed php data by sending it to the browser as an out put. You can display the contents within the browser to see the users. There are several ways allows in php to send out put to the browser. I'm discussed here most important & common methods here.
- echo() statement
This is the most common out put generation method in php. echo() statement accept multiple arguments.
syntax:
echo (string arg1[, string arg2, ...]);
PHP - Arrays
There are two types of array namely,
$bookName = "Sample Book";
$bookAuthor = "Author\'s Name";
$bookPublished = "April 02, 2013";
$bookPublisher = "Sample Book Publisher";
But you can store above all values to a single array.
- Single Dimensional Array
- Multi Dimensional Array
$bookName = "Sample Book";
$bookAuthor = "Author\'s Name";
$bookPublished = "April 02, 2013";
$bookPublisher = "Sample Book Publisher";
But you can store above all values to a single array.
- Single Dimensional Arrays
Ex:
$book = array(
"Sample Book",
"Author's Name",
"April 02, 2013",
"Sample Book Publisher"
) //use a book array to store above values
echo "Book Name : " . $book[0]; // Print 1st element of the array
PHP - Numbers
There are two types of Numbers can be declared with php.
- Whole Numbers
Integer data type uses to store positive or negative whole Numbers (without decimal points). It is not required to define integers because php is a loosely typed language. You are define a whole number without double quotes then it automatically evaluate as an integer value. But you can force the value store as integer by using casting.Ex:
1, -50
$num = 50 // Numbers are define without double or single quotes
$num = (int) 50 // This is a casting example. Here force to store the value as integer.
$num = (int) "5years" // Taken the value as 5
$num = (int) "age10" // Taken the value as 0 - Real Numbers
Double and Float data type uses to store positive or negative whole Numbers (with decimal points).
Ex:
15.3325, -5.586240
$num = 50.5589// Real Numbers are define without double or single quotes
$num = (double) 50.569 // This is a casting example. Here force to store the value as real number.
$num = (double) "5.85Km" // Taken the value as 5.85
$num = (double) "age10.6" // Taken the value as 0
$num = (float) "10.53yards" // Taken the value as10.53
PHP - String
String Variables are used to store set of characters enclosed with single (') or double (") quotes. In this post covering general operations and operations of string.
Ex:
<?php
$str = "PHP programing with String"; // Assign characters to string variable
echo $str; // Print the string
?>
Out put:
PHP programing with String
Ex:
<?php
$str = "PHP programing with String"; // Assign characters to string variable
echo $str; // Print the string
?>
Out put:
PHP programing with String
- String Concatenation
You can put two or more strings together with (.) operator.
Ex:
<?php
$str1 = "PHP Programing";
$str2 = " with String";
echo $str1 . $str2;
?>
Out put:
PHP programing with String
PHP - Arithmetic Operations
- Addition (+)
Addition is performed with the "+" symbol.
Ex:
$total = 5 + 6;
Here 5 add to 6 and assign to the total variable
- Subtract (-)
Subtract is performed with the "-" symbol.
Ex:
$answer = 8 - 6;
- Multiplication (*)
Multiplication is performed with the "*" symbol.
Ex:
$answer = 5 * 6;
PHP - Variables and Data types
What is a Variable?
Variables are used to store values into the system's memory. Variables allows to perform set of actions and can be re-use within the code. You can change the out put of the program by changing the variable values rather changing the script.
Data Types
String : used for character values such as sentences, names stc
Integer : used to store numeric values of whole numbers
Float : used to store numeric values of real numbers
Boolean: used to store either true or false or 1 or 0
Object : used to store collection of values (data) or methods
Important: PHP is loosely typed language, that means your script determines the data type of the variable.
Ex:
$val = "PHP Programming" // This is considering as String Value
$val = 50 // This is considering as Integer Value
$val = "100" //This is considering as String value
$val = $val * 5 // This is considering as Integer value
$val = $val * 1.25 //This is considering as float value
PHP - Embeded HTML
This post desribe about the PHP scripting, html coding and embedded php scripts.
I'll explain those with an example.
<html>
<head>
<title>Embedded php</title>
</head>
<body>
<hr />
<h3>Embedded php</h3>
<p>This is a regular HTML paragraph</p>
<?php
echo "<p>This is a php paragraph</p>";
?>
<hr />
</body>
</html>
Above code displays following output.
This is a php paragraph.
I'll explain those with an example.
<html>
<head>
<title>Embedded php</title>
</head>
<body>
<hr />
<h3>Embedded php</h3>
<p>This is a regular HTML paragraph</p>
<?php
echo "<p>This is a php paragraph</p>";
?>
<hr />
</body>
</html>
You can see the text inside the php script and out side it. Text inside the php script (comes with echo statement) handled as a script and rest of the text rendered as regular HTML. We can include any no of php blocks inside the html document like java script and any html tag to embedded the code.
Embedded php
This is a regular HTML paragraphThis is a php paragraph.
PHP - Install a Web Server
- Wamp Server
This video instruct you how to install wamp server - Xampp server
This video instruct you how to setup xampp server on linux (Fedora)
Subscribe to:
Posts (Atom)