php code showing in browser rather than rendered html

Beginner level developers may experience this problem when they start learning php. If your php script is displaying on your browser instead of showing output, then you may check the following thing.

1. Make sure that your url not starting like file:///C:/ , This is so funny but sometimes it happens with some developers. Your url pattern must starts with http:// 

2. Check your PHP installation is working properly. This can be done by just open the terminal or command prompt and type php -v and hit enter button. It must return your installed php version like PHP 7.0.0 

3. Confirm that the PHP module is listed and uncommented inside of your Apache’s httpd.conf This should be something like LoadModule php5_module “c:/php/php5apache2_2.dll” in the file. Search for LoadModule php, and confirm that there is no comment (;) in front of it.

4. Confirm that Apache’s httpd.conf file has the PHP MIME type in it. This should be something like AddType application/x-httpd-php .php. This tells Apache to run .php files as PHP. Search for AddType, and then make sure there is an entry for PHP, and that it is uncommented.

5. Confirm your file has the .php extension on it, or whichever extension specified in the MIME definition in point #3, otherwise it will not be executed as PHP.

6. Confirm you are not using short tags in the PHP file ( Make sure you are accessing your file over your webserver using an URL like http://localhost/file.php not via local file access file://localhost/www/file.php
And lastly check the PHP manual for further setup tips.

7. Confirm that you have’t accidentally saved my script in UTF-16 encoding. PHP5 can’t recognize <?php tag in 16 bit encoding by default.

Note for php 7 users, add this to your httpd.conf file:

# PHP 7 specific configuration
<IfModule php7_module>
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    <IfModule dir_module>
        DirectoryIndex index.html index.php
    </IfModule>
</IfModule>


Google’s libphonenumber library supported country list

Recently i developed an ionic2 application, in this app i wanted to validate the phone number based on the country selection, for this purpose i used  libphonenumber from google. It worked just fine when i tried this with few country lists with its ISO codes. But real problem starts when i used all the list of countries, application just throw an error like below

Runtime Error
Error in ./LoginPage class LoginPage – caused by: Cannot read property ‘getNationalNumber’ of null
 Cannot read property 'getNationalNumber' of null

After doing some debugging, i just removed the list of countries which does not support by this google library. I have given below the list of countries supported by this google library.

[“AF”, “Afghanistan”],
[“AL”, “Albania”],
[“DZ”, “Algeria”],
[“AD”, “Andorra”],
[“AO”, “Angola”],
[“AI”, “Anguilla”],
[“AG”, “Antigua and Barbuda”],
[“AR”, “Argentina”],
[“AM”, “Armenia”],
[“AW”, “Aruba”],
[“AU”, “Australia”],
[“AT”, “Austria”],
[“AZ”, “Azerbaijan”],
[“BS”, “Bahamas”],
[“BH”, “Bahrain”],
[“BD”, “Bangladesh”],
[“BB”, “Barbados”],
[“BY”, “Belarus”],
[“BE”, “Belgium”],
[“BZ”, “Belize”],
[“BJ”, “Benin”],
[“BM”, “Bermuda”],
[“BT”, “Bhutan”],
[“BO”, “Bolivia”],
[“BA”, “Bosnia and Herzegovina”],
[“BW”, “Botswana”],
[“BR”, “Brazil”],
[“IO”, “British Indian Ocean Territory”],
[“BN”, “Brunei Darussalam”],
[“BG”, “Bulgaria”],
[“BF”, “Burkina Faso”],
[“BI”, “Burundi”],
[“KH”, “Cambodia”],
[“CM”, “Cameroon”],
[“CA”, “Canada”],
[“CV”, “Cape Verde”],
[“KY”, “Cayman Islands”],
[“CF”, “Central African Republic”],
[“TD”, “Chad”],
[“CL”, “Chile”],
[“CN”, “China”],
[“CX”, “Christmas Island”],
[“CC”, “Cocos (Keeling), Islands”],
[“CO”, “Colombia”],
[“KM”, “Comoros”],
[“CG”, “Congo”],
[“CK”, “Cook Islands”],
[“CR”, “Costa Rica”],
[“HR”, “Croatia (Hrvatska)”],
[“CU”, “Cuba”],
[“CY”, “Cyprus”],
[“CZ”, “Czech Republic”],
[“DK”, “Denmark”],
[“DJ”, “Djibouti”],
[“DM”, “Dominica”],
[“DO”, “Dominican Republic”],
[“EC”, “Ecuador”],
[“EG”, “Egypt”],
[“SV”, “El Salvador”],
[“GQ”, “Equatorial Guinea”],
[“ER”, “Eritrea”],
[“EE”, “Estonia”],
[“ET”, “Ethiopia”],
[“FK”, “Falkland Islands (Malvinas)”],
[“FO”, “Faroe Islands”],
[“FJ”, “Fiji”],
[“FI”, “Finland”],
[“FR”, “France”],
[“GF”, “French Guiana”],
[“PF”, “French Polynesia”],
[“GA”, “Gabon”],
[“GM”, “Gambia”],
[“GE”, “Georgia”],
[“DE”, “Germany”],
[“GH”, “Ghana”],
[“GI”, “Gibraltar”],
[“GR”, “Greece”],
[“GL”, “Greenland”],
[“GD”, “Grenada”],
[“GP”, “Guadeloupe”],
[“GU”, “Guam”],
[“GT”, “Guatemala”],
[“GN”, “Guinea”],
[“GW”, “Guinea-Bissau”],
[“GY”, “Guyana”],
[“HT”, “Haiti”],
[“HN”, “Honduras”],
[“HK”, “Hong Kong”],
[“HU”, “Hungary”],
[“IS”, “Iceland”],
[“IN”, “India”],
[“IM”, “Isle of Man”],
[“ID”, “Indonesia”],
[“IR”, “Iran (Islamic Republic of)”],
[“IQ”, “Iraq”],
[“IE”, “Ireland”],
[“IL”, “Israel”],
[“IT”, “Italy”],
[“CI”, “Ivory Coast”],
[“JE”, “Jersey”],
[“JM”, “Jamaica”],
[“JP”, “Japan”],
[“JO”, “Jordan”],
[“KZ”, “Kazakhstan”],
[“KE”, “Kenya”],
[“KI”, “Kiribati”],
[“KP”, “Korea, Democratic People`s Republic of”],
[“KR”, “Korea, Republic of”],
[“KW”, “Kuwait”],
[“KG”, “Kyrgyzstan”],
[“LA”, “Lao People`s Democratic Republic”],
[“LV”, “Latvia”],
[“LB”, “Lebanon”],
[“LS”, “Lesotho”],
[“LR”, “Liberia”],
[“LY”, “Libyan Arab Jamahiriya”],
[“LI”, “Liechtenstein”],
[“LT”, “Lithuania”],
[“LU”, “Luxembourg”],
[“MO”, “Macau”],
[“MK”, “Macedonia”],
[“MG”, “Madagascar”],
[“MW”, “Malawi”],
[“MY”, “Malaysia”],
[“MV”, “Maldives”],
[“ML”, “Mali”],
[“MT”, “Malta”],
[“MH”, “Marshall Islands”],
[“MQ”, “Martinique”],
[“MR”, “Mauritania”],
[“MU”, “Mauritius”],
[“MX”, “Mexico”],
[“FM”, “Micronesia, Federated States of”],
[“MD”, “Moldova, Republic of”],
[“MC”, “Monaco”],
[“MN”, “Mongolia”],
[“ME”, “Montenegro”],
[“MS”, “Montserrat”],
[“MA”, “Morocco”],
[“MZ”, “Mozambique”],
[“MM”, “Myanmar”],
[“NA”, “Namibia”],
[“NR”, “Nauru”],
[“NP”, “Nepal”],
[“NL”, “Netherlands”],
[“NC”, “New Caledonia”],
[“NZ”, “New Zealand”],
[“NI”, “Nicaragua”],
[“NE”, “Niger”],
[“NG”, “Nigeria”],
[“NU”, “Niue”],
[“NF”, “Norfolk Island”],
[“MP”, “Northern Mariana Islands”],
[“NO”, “Norway”],
[“OM”, “Oman”],
[“PK”, “Pakistan”],
[“PW”, “Palau”],
[“PS”, “Palestine”],
[“PA”, “Panama”],
[“PG”, “Papua New Guinea”],
[“PY”, “Paraguay”],
[“PE”, “Peru”],
[“PH”, “Philippines”],
[“PL”, “Poland”],
[“PT”, “Portugal”],
[“PR”, “Puerto Rico”],
[“QA”, “Qatar”],
[“RE”, “Reunion”],
[“RO”, “Romania”],
[“RU”, “Russian Federation”],
[“RW”, “Rwanda”],
[“KN”, “Saint Kitts and Nevis”],
[“LC”, “Saint Lucia”],
[“VC”, “Saint Vincent and the Grenadines”],
[“WS”, “Samoa”],
[“SM”, “San Marino”],
[“ST”, “Sao Tome and Principe”],
[“SA”, “Saudi Arabia”],
[“SN”, “Senegal”],
[“RS”, “Serbia”],
[“SC”, “Seychelles”],
[“SL”, “Sierra Leone”],
[“SG”, “Singapore”],
[“SK”, “Slovakia”],
[“SI”, “Slovenia”],
[“SB”, “Solomon Islands”],
[“SO”, “Somalia”],
[“ZA”, “South Africa”],
[“ES”, “Spain”],
[“LK”, “Sri Lanka”],
[“SH”, “St. Helena”],
[“PM”, “St. Pierre and Miquelon”],
[“SD”, “Sudan”],
[“SR”, “Suriname”],
[“SJ”, “Svalbard and Jan Mayen Islands”],
[“SZ”, “Swaziland”],
[“SE”, “Sweden”],
[“CH”, “Switzerland”],
[“SY”, “Syrian Arab Republic”],
[“TW”, “Taiwan”],
[“TJ”, “Tajikistan”],
[“TZ”, “Tanzania, United Republic of”],
[“TH”, “Thailand”],
[“TG”, “Togo”],
[“TK”, “Tokelau”],
[“TO”, “Tonga”],
[“TT”, “Trinidad and Tobago”],
[“TN”, “Tunisia”],
[“TR”, “Turkey”],
[“TM”, “Turkmenistan”],
[“TC”, “Turks and Caicos Islands”],
[“TV”, “Tuvalu”],
[“UG”, “Uganda”],
[“UA”, “Ukraine”],
[“AE”, “United Arab Emirates”],
[“GB”, “United Kingdom”],
[“US”, “United States”],
[“UY”, “Uruguay”],
[“UZ”, “Uzbekistan”],
[“VU”, “Vanuatu”],
[“VA”, “Vatican City State”],
[“VE”, “Venezuela”],
[“VN”, “Vietnam”],
[“VG”, “Virgin Islands (British)”],
[“VI”, “Virgin Islands (U.S.)”],
[“WF”, “Wallis and Futuna Islands”],
[“EH”, “Western Sahara”],
[“YE”, “Yemen”],
[“ZM”, “Zambia”],
[“ZW”, “Zimbabwe”]

this plugin not support the following countries

[“DS”, “American Samoa”]
[“AQ”, “Antarctica”]
[“BV”, “Bouvet Island”]
[“TP”, “East Timor”]
[“FX”, “France, Metropolitan”]
[“TF”, “French Southern Territories”]
[“GK”, “Guernsey”]
[“HM”, “Heard and Mc Donald Islands”]
[“XK”, “Kosovo”]
[“TY”, “Mayotte”]
[“AN”, “Netherlands Antilles”]
[“PN”, “Pitcairn”]
[“GS”, “South Georgia South Sandwich Islands”]
[“UM”, “United States minor outlying islands”]
[“ZR”, “Zaire”]

I hope this will help someone,

Thanks

Arrays in PHP

An array is a collection of values in a single variable name.The variables in an array is called the array elements.Array elements are accessed using a single name and an indexed number represending the postion of the elements with in the array.The lenght of an array will be less than the actual length.Since index is starts with zero.We can insert the values for each elemnets in an array by using a subscript as follows,

<?php
$a [0] = “apple”;
$a [1] = “cherry”;
$a [2] = “plum”;
?>

We can also use array() function to declare an array of predifined values

<?php
$a = array(“apple”,”cherry”,”plum”);
?>

Values taken from the array is similar to assign values to the array.
<?php
$abc = $a[2];
?>
Now the value of the variable $abc will be “plum” , Loops are widely used to manipulate the arrays.The following code is used for assigning and printing the values in an array.
<?php
for($i=1;$i<=10;$i++) { $arr [$i] = $i*$i; echo $arr [$i]; }
?>
There are three types of arrays in php:-

  1. Numeric(Indexed) array – An array with a numeric index
  2. Associative array – An array where each ID key is associated with a value
  3. Multidimensional array – An array containing one or more arrays

Numeric Array

Numeric or Indexed array has numeric keys that start with zero.Any kind of values can be assigned in the elements of the array.The following code shows how to assigning values to an indexed array.
<?php
$a = array(“apple”,”cherry”,”plum”);
?>
Or
<?php
$a [0] = “apple”;
$a [1] = “cherry”;
$a [2] = “plum”;
?>

Associative Array

In associative array we can use user defined keys (named keys) for assigning values to the array.The usage of associative array is given below.
<?php
$a[“apple”]=”Rs.72″;
$a[“grape”]=”Rs.152″;
$a[“cherry”]=”Rs.350″;
?>

Multidimensional Array

A multidimensional array is an array that contains at least one other array as the value of one of the indexes.

<?php
$MDA= array(
“A” => array(0 => “red”, 2 => “blue”, 3 => “green”),
“B” => array(1 => “orange”, 2 => “black”),
“C” => array(0 => “white”, 4 => “purple”, 8 => “grey”)
);echo $MDA[“A”][3]; // green
echo “<br>”;
echo $MDA[“C”][8]; // grey
?>

Functions in PHP

Besides control and variables are PHP scripts through function calls. If the same code is executing this program code is often outsourced to a function. So instead of having the same code every time you call in the appropriate places on only the function, which then performs the actual work.<?php?>

sin(3.1415);

The behavior of a function is affected by their parameters. A function can have any number of parameters, including parameters not exactly as an infinite number of parameters. Further, a function return value. This is also the standard use of a function, it will pass parameters and the function returns a value based on this back. For example, the sin function returns the sine of the given radian value.

Define your own functions<? Php?><? Php?><? Php?><? Php   / / Here now follows}For typical programming style to indent the code within the function by 4 spaces. Thus it can be seen where the function starts (the function keyword) and where it ends (at the closing brace}).<? Php   echo $ var / / help, where is defined $ var?$ Var = ‘HTML’;                / / Super globals are available3 Optional parameters<? Php   echo ‘x has the value: “‘ $ x.. ‘” test and has the value: “‘ $ test.. ‘”‘;myFunction (4, ‘word’) / / outputs 4 and word ofmyFunction () / / not possible since at least one parameter is required?>Although you use any functions in PHP code, as well as echo, it is customary return a calculated value for a function. This is implemented in PHP with the language construct return. It got to a value or a variable that you want to return.function myFunction () {   return 300;}?>It is also possible to exit a function and return with it to indicate no return value. This makes only sense if not expected is that a function has a return value.function myFunction () {   return;myFunction () / / works without problems?>Functions that are provided by PHP described in detail on the official website. Accordance with specially created features missing such a documentation. You may guess the functionality of the function name. For complex functions are hoping for a good documentation. For this purpose they PHPDocs. Before the actual function to add a PHPDoc comment which describes the function./ **** Square of this function back.* @ Param x The value of the you want to have a perfect square* /   return $ x * $ x;?>Array is a special variable in php, it is used to store multiple values in a single varible. I f you want to store a list data, you can store these values in a sigle variable as followsor$car [0]= “BMW”;array() is used to declare an array in php, There are three types of arrays available in php.Indexed, Associative, Multidimensional are the three types of arrays

$car [0]= “Nizan”;

$car [0]= “Maruthi”;

$car =  array(“maruthi”,”BMW”,”Nizan”);

Array in php

}

function square ($ x) {

* @ Return The number of square

*

* This function is passed a parameter and returns

* Returns a square number.

<? Php

5 Documentation of own functions

My $ var = function () / / works, $ var got the value NULL (a special data type)

}

/ / Code anderere

<? Php

With the return function is terminated at the same time. This can be done at any point, if it makes sense. In calculating the sine of the value 0 for example be expected not great but there is a case distinction quite early to the value 0 is returned.

echo myFunction () / / outputs 300 from

mach_das () / / is not running, as was leaving the function / closed

do_that () / / is still running

<? Php

4 Return value of functions

myFunction (1, 2, 3) / / possible, but the third parameter is lost

myFunction (5) / / outputs 5 and foobar

}

function myFunction ($ x, $ test = ‘foobar’) {

In PHP, it is allowed to define which one is not used later in a function call parameters. Thus it is e.g. possible to call the function although theoretically supports 3 parameters a function with only one parameter. So as to define a function assigns default values ​​to the parameters in the parameter list. It is done by specifying an assignment for the parameter. When the function is called with a parameter value that is used for the variable parameters. When the function is called without the parameter as the parameter variable contains the specified default value.

?>

myFunction () / / will not work because the only function parameters and variables

}

function myFunction () {

Within the function, the parameter variables can be used. In addition to the superglobal variables no further variables are otherwise available. This is called also variable scope. The variable parameters are then filled in accordance with the values ​​of the function call. If the parameters for the function are variables whose values ​​are passed, but not the variable itself in first place, it is therefore not possible to change variables that are used outside the function.

?>

/ / Normal php code

function myFunction ($ param1, $ param2) {

The contents of the function starts with an opening curly brace {. Now you can write any PHP code. At the end of the function body ends with a closing curly chamber }.

function myFunction ($ param1, $ param2)

Like a function call now follows an open parenthesis (. According to the clamp can now variables for the parameters are given. With the number of variables (comma separated) so you need to decide the number of parameters. However if you are planning a function with any to define many parameters you are at this point no parameters at all and use the functions in the function body func_get_args, func_get_arg and func_num_args. The parameter list is then finished with the closing parenthesis).

function myFunction

This is followed by the actual name of the function. The name itself is subject to common rules such as not begin with numbers. Furthermore, the functions have two underscores (__) begin special functionality. You should use this function only when they want exactly the functionality that is described in the manual.

function

Sooner or later we want not only the functionality provided by using special PHP define your own functions. A function definition starts with the keyword function in PHP.

Loops

Sometimes we need execute some code repetitively based on a condition. In this situation we can use loops to perform that task.

In PHP, we have the following looping statements:

  • while – loops through a block of code until specified condition is true
  • do…while – loops through a block of code once, and then repeats the loop until the specified condition is true
  • for – loops through a block of code a specified number of times
  • foreach – loops through a block of code for each element in an array

while loop

The while loop is used to execute a block of statements for a definite number of times, depending on a condition. The while loop statement always checks the condition before executing the statement with in the loop.The loop will continues its the execution until the condition evaluates to false.

Example

<?php

$a=1;

while($a<=10)

{

echo “The number is:     $a<br>”;

$a++;

}

?>

do … while Loop

This loop is a same as the while loop, The do  block will executes at least once in the begining of the loop.

do

{

 code to be executed;

 }

while (condition is true);

 

For loop

The for loop is used to execute the code for a specific number of times.The same procedure as for loop.

for (init counter; test counter; increment counter)

{

code to be executed;

}

The initialization expression initialize the expression for the for loop statement.It executes once at the begining of the loop. The termination expression determines when to terminate the while loop. At the beginning of the loop, this expression evaluated for each iteration. if the expression evaluates to false, the loop terminates. Then, the decrement/increment expression gets invoked after each iteration.

foreach Loop

The foreach loop only used to loop through array, It iterate for each key/value pair in an array.

foreach ($array as $value)

{

code to be executed;

}

Conditional Statements

If else statement

The if .. else construct is used to take decision based on the Boolean result that return by a logical expression.

 

We can use the if …else block as following examples.

 

Example 1

if ($val==1)

{

        echo “The result is 1”;

 }

Example 2

if ($val==’Ram’)

{

        echo “Your name is Ram”;

 }

else

{

echo “Your are not Ram”;

}

Example 3

if ($val==’Ram’)

{

        echo “Your name is Ram”;

 }

else if ($val==’Jo’)

{

echo “Your name is jo”;

}

else

{

echo “Name not found”;

}

switch case statement

switch case is the another conditional statement in php.It is used when we need to compare multiple values of a variable. You can use the switch case statement as following.

<?php

$name=”Sijo”;

switch ($name)

{

case “Sijo”:

echo “Your name is Sijo”;

break;

case “Dinson”:

echo “Your name is Dinson”;

 

break;

case “Manu”:

echo “Your name is Manu”;

break;

default:

echo “Name not faound”;

}

?>

Whenever the switch statement is executed,the variable given in the switch statement is evaluated and compared with each case constant. If one of the case constant is equal to the value of the variable given in the switch statement, control is passed to the statement following the matched case label. A break  statement is used to exit the switch statement.If none of the cases match,the default case is invoked.

Comments in PHP

We can write comments in php script like the following

<?php

// This type comment is used to write a single line comment

echo “Hello php”;

/*

This is

a PHP comment

block

*/

?>

Operators in php

Php applications use operators to process the data that entered by a user or fetch from the database. Operators like + and – are used to process variables and return a value. It is used for computations or comparisons and it may contain one or more characters. Operators can transform one or more data values called operands, into a new data value.

Consider the following example:

$a+$b

The preceding example uses two operands and an operator to add the values stored in the variables.

Following operators used in php

1.      Arithmetic operators

2.      Assignment operators

3.      Unary operators

4.      Comparison operators

5.      Logical operators

6.      Array operators

 

Arithmetic operators

These operators are the symbols that are used to perform arithmetic operations on the php variables. The following table describes the commonly used arithmetic operators.

Operators Description Example
+ Used to add to numbers $a = $b+$c;

If  $b is equal to 10 and $c is equal to 5,Then $a will be 15

Used to subtract two numbers $a = $b-$c;

If  $b is equal to 10 and $c is equal to 3,Then $a will be 12

* Used to multiple two numbers $a = $b*$c;

If  $b is equal to 8 and $c is equal to 5,Then $a will be 40

/ Used to divide one number by another $a = $b/$c;

If  $b is equal to 8 and $c is equal to 2,Then $a will be 4

% Used to divide two numbers and return the reminder $a = $b%$c;

If  $b is equal to 21 and $c is equal to 2,Then $a will be 1

 

Assignment operators

These operators are used to perform arithmetic operations to assign a value to an operand. Left operand gets set to the value of the expression on the right.

Example Usage Description
= $a = 10; Stores the value 10 in the variable $a

 

+= $a += $b; Same as

$a = $a +$b;

-= $a -= $b; Same as

$a = $a – $b;

*= $a *= $b; Same as

$a = $a * $b;

/= $a /= $b; Same as

$a = $a / $b;

%= $a %= $b; Same as

$a = $a % $b;

Unary operators

These operators are used to increment or decrement the value of an operand by1. The following table explain the usage of the increment and decrement operators.

operator Description Example
++ Used to increment the value of an operand by 1 $a = $b++;

 

Used to decrement the value of an operand by 1 $a = $b–;

 

 

Comparison operators

These operators are used to compare two values and execute a code block or an action on the basis of the result of that comparison. The result of the comparison operator will be ‘true’ or ‘false’

Operator Usage Description Example
< expression1 < expression2 It is used to check whether expression1 is less than expression2 $x < $y

True if $x is less than $y

> expression1 > expression2 It is used to check whether expression1 is greater expression2 $x > $y

True if $x is greater than $y

<= expression1 <= expression2 It is used to check whether expression1 is less than or equal to expression2 $x <= $y

True if $x is less than or equal to $y

>= expression1 >= expression2 It is used to check whether expression1 is greater than or equal to expression2 $x >= $y

True if $x is greater than or equal to $y

== expression1 == expression2 It is used to check whether expression1 is equal to expression2 $x == $y

True if $x is equal to $y

!= expression1 != expression2 It is used to check whether expression1 is not equal to expression2 $x != $y

True if $x is not equal to $y

=== expression1 === expression2 It is used to check whether expression1 is identical to expression2 $x === $y

True if $x is equal to $y, and they are of the same type

 

Logical operators

These operators are used to evaluate expressions and return a boolean value.

Operator Usage Description Example
&& expression1 && expression2 It returns true, if both expression1 andexpression2 are true. $x && $y

True if both $x and $y are true

! ! expression It returns true, if expression is false. !$x

True if $x is not true

|| expression1 || expression2 It returns true, if either expression1 or expression2 or both of them are true. $x || $y

True if either $x or $y is true

PHP variables

A variable is a memory location to store a value.In PHP the value may be a string,number,flot,array even an object of a class etc. A variable begins with the $ sign

Rules for declare PHP variables:

  • A variable begins with the $ sign,followed by its name
  • A variable name must start with a letter or _ charactor
  • A variable name can only contain letters , number and _ charactor (A-z,0-9, and _)
  • Variable names are case sensitive $y not equal $Y

System allocated a space for a variable only when you assign a value for it

<?$txt="Hello world!";
$x=5;?> .

Syntax

A php script can be write anywere in the file, A php script starts with <?php and end with ?>
example: <?php echo “Hello world”; ?>
This script print “Hello world” in your browser as output. The echo is a function used to print a value in the out put htmlEvery code line in PHP must end with a semicolon. The semicolon is a separator between the instructions from another.If you forgot to put a semicolon,php compiler will return an error (common mistakes in programming)

In PHP, there are two basic statements to print anything in the web browser: echo and print.

PHP Introduction

PHP is a programming language,It is used for making dynamic and interactive Web pages. PHP is a widely-used, free ans easy to learn.Before you continue you should have a basic knowledge in HTML and javascript.whenever we need to create a dynamic html file, we need to create a file contain our program logic as a php script with .php as the extension, we can add html tags and javascript etc in the same file.PHP file can open,read or close file in server and establish a database connection and query something from the database, anything can do like other scripting languages such as ASP,JSP etc

The php script executed on the web server such as apache server and return html to the browser

Syntax

A php script can be write anywere in the file, A php script starts with <?php and end with ?>
example: <?php echo “Hello world”; ?>
This script print “Hello world” in your browser as output. The echo is a function used to print a value in the out put html

Every code line in PHP must end with a semicolon. The semicolon is a separator between the instructions from another.If you forgot to put a semicolon,php compiler will return an error (common mistakes in programming) .In PHP, there are two basic statements to print anything in the web browser: echo and print.