Posts

Differences

Image
Differences between constants and variables are as fallow:- There is no need to write a dollar sign ($) before a constant, where as in Variable one has to write a dollar sign. Constants cannot be defined by simple assignment, they may only be defined using the define() function. Constants may be defined and accessed anywhere without regard to variable scoping rules. Once the Constants have been set, may not be redefined or undefined.

Constants

Image
A Constant is a name or an Identifier for a simple Value. A Constant value cannot change during the Execution of the Script. By default, a constant is case sensitive. By convention, constant identifiers are always uppercase. A constant name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. If you have defined a constant, it can never be changed or undefined. To define a constant you have to use define() function and to retrieve the value of a constant, you have to simply specifying its name. Unlike with variables, you do not need to have a constant with a $. You can also use the function constant() to read a constant's value if you wish to obtain the constant's name Dynamically. constant() function As indicated by the name, this function will return the value of the constant. This is useful when you want to retrieve value of a constant, but you do not know its name, i.e. It is stored in a variable or returned by a f

Variables

Image
Variables are used to Store Information to be referenced and manipulated in a program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as Containers that hold information. Their sole purpose is to label and store data in memory. This data can then be used throughout your program... Here are the most important things to know about variables in 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. Variables in PHP do not have intrinsic types - a variable does not know in advance whether it will be used to store a number or a string of characters. Variables used before

Lecture # 3 Comments:-

Image
Commenting in PHP A Comment is a Programmer's Readable Explanation or Annotation in the Source Code of a Program. They are added with the purpose of making the Source Code Easier for Humans to understand, and are generally ignored by Compilers and Interpreters. Uses Planning and Reviewing Code Description Algorithmic Description Resource inclusion Metadata Debugging Automatic Documentation Generation Syntax Extension Stress Relief There are two commenting formats in PHP - 1. Single Line Comments 2. Multi Line Comments Single-line Comment They are generally used for short Explanations or notes relevant to the local code. Here are the examples of single line Comments. <?php      # This is a comment, and      # This is the second line of the comment       // This is a comment too. Each style comments only print           "An example with single line comments";  ?> Multi-lines Comments They are g

Php Syntax Detail Discussion

This chapter will give you an idea of very basic syntax of PHP and very important to make your PHP foundation strong. Escaping to PHP The PHP parsing engine needs a way to differentiate PHP code from other elements in the page. The mechanism for doing so is known as 'escaping to PHP'. There are four ways to do this − Canonical PHP tags The most universally effective PHP tag style is − <?php...?> If you use this style, you can be positive that your tags will always be correctly interpreted. Short-open (SGML-style) tags Short or short-open tags look like this − <?...?> Short tags are, as one might expect, the shortest option You must do one of two things to enable PHP to recognize the tags − Choose the --enable-short-tags configuration option when you're building PHP. Set the short_open_tag setting in your php.ini file to on. This option must be disabled to parse XML with PHP because the same syntax is used for XML tags. ASP-style t

Basic Php Syntax and First Example

A PHP script can be placed anywhere in the document. A PHP script starts with <?php and ends with ?> Example:                <?php                   // PHP code goes here                ?> The default file extension for PHP files is ".php". A PHP file normally contains HTML tags, and some PHP scripting code. Below, we have an example of a simple PHP file, with a PHP script that uses a built-in PHP function "echo" to output the text "Hello World!" on a web page: Example:                 <!DOCTYPE html>                 <html>                 <body>                  <h1>My first PHP page</h1>                  <?php                  echo "Hello World!";                  ?>                  </body>                  </html>

Uses of PHP

PHP performs system functions, i.e. from files on a system it can create, open, read, write, and close them. PHP can handle forms, i.e. gather data from files, save data to a file, through email you can send data, return data to the user. You add, delete, modify elements within your database through PHP. Access cookies variables and set cookies. Using PHP, you can restrict users to access some pages of your website. It can encrypt data.