Escolar Documentos
Profissional Documentos
Cultura Documentos
Ans 1 -PHP is a server-side scripting language designed primarily for web development but also
used as a general-purpose programming language. Originally created by Rasmus Lerdorf in 1994,
[4]
the PHP reference implementation is now produced by The PHP Development Team.[5] PHP
originally stood for Personal Home Page,[4] but it now stands for the recursive acronym PHP:
Hypertext Preprocessor.[6]
PHP code may be embedded into HTML or HTML5 code, or it can be used in combination with
various web template systems, web content management systems and web frameworks. PHP code
is usually processed by a PHP interpreter implemented as a module in the web server or as
a Common Gateway Interface (CGI) executable. The web server combines the results of the
interpreted and executed PHP code, which may be any type of data, including images, with the
generated web page. PHP code may also be executed with a command-line interface (CLI) and can
be used to implement standalone graphical applications.[7]
The standard PHP interpreter, powered by the Zend Engine, is free software released under
the PHP License. PHP has been widely ported and can be deployed on most web servers on almost
every operating system and platform, free of charge.[8]
The PHP language evolved without a written formal specification or standard until 2014, leaving the
canonical PHP interpreter as a de facto standard .
System comments using in PHP -This is an Ajax base Comment System and it is an
advance script where the users of your websites can easily post their comments or replies on your
updates or other information on your website using Ajax, and PHP.
The comment system uses cookie to store users information on their first time to post a comment,
reply to a posted comment or like a comment and these stored information are later saved in the
database as the login information for your users.
For a user to leave or post a comment, reply to a posted comment or like a comment, the system will
prompt the user to enter his or her Full name and Email Address for identification purpose.
The system uses the email addresses submitted by users at their first time to post a comment, reply
to a posted comment or like a comment to identify them whenever they try to perform any further
action in the future and as such, users email addresses are unique within the system.
some features of the comment system:
(3) Users can add their avatar or desired photo for commenting purpose
(8) Send a notification email to admin for every new comment posted for moderation purpose
(9) Nice display of Confirmation Box for comment deletion and logout
(10) Proper validation for empty fields and invalid email addresses
(11) Comments are displayed based on pages where they are posted
(12) No long URLs or contents that extends through the comments box area.
(13) Auto Load more Comments when the page is scrolled down
(15) Admins can moderate comments by deleting unwanted comments or editing a user comment
that is not formatted properly
(18) You can add videos in comments and supported videos are YouTube, Vimeo, Metacafe, Daily
motion and Flicker.
This powerful comment system supports all modern browsers and programming languages used are
Ajax, Jquery, PHP and MySqli procedural method for the database queries.
The system comes with a language file to enable you easily change the text used throughout the
comment system to suit your needs.
Q.2. How many types of Variables and data types use in PHP Scripts?
Ans 2-Variables in PHP -
PHP also has variables and constants just like other programming languages such as C,
Java, and BASIC. Variables are the storage spaces where you can store values for later
use. They act as identifiers to access memory locations.
In PHP, variable names begin with a dollar ($) sign, whereas assignment is carried out
by using = operator. Furthermore, all statements end up with a semi-colon (;) sign
that indicates the termination of the statement. Another benefit of PHP is that we dont
need to specify the data type using keywords like int, char, float, double or string.
Example:
<?php
$a=5;
$a=$a+5;
echo $a;
?>
Output: 10
<?php
$integer_num=10; // Integer Value
?>
Invalid Syntaxes
Like in any other computing language, PHP has its share of invalid syntaxes.
Example
$2name=10; //Invalid because you cant start a variable name with a number.
1. Object
PHP lets you create objects that comprise of functions and variables. Arrays and
functions are examples of objects. We will be discussing this data type in detail when we
cover object-oriented programming in PHP. This data type not only stores data, but it
can also record the information on how to process data.
Example
<?php
class webhosting {
function webhosting() {
$this->servicename = cloudways;
// create an object
echo $cloud->servicename;
?>
Output
cloudways
2. Arrays
Array is another type of variable where you can store a set of values in a single variable.
Arrays are declared using the keyword array. There are 3 different types of arrays:
Indexed arrays: They consists of numeric index.
Example
<?php
?>
Output
3. Resources
Resources are special variables dedicated for storing external resources of PHP; for e.g.,
connections of database. I will touch upon resources when covering advanced topics as
it is not an actual data type.
4. Integers
Integers are whole numbers without a decimal point; e.g., 4195. They are the simplest
of the data types. Integers correspond to simple whole numbers, both positive and
negative. Expressions can also be used in variable declaration.
Example
<?php
$int_exp= 345-343;
var_dump($int_exp);
?>
Integers can be declared using hexadecimal, octal and decimal format. By default, it is
in decimal format.
5. Doubles -
All decimal containing numbers or floating-point numbers fall under this data type, for
example, 34.4. It automatically prints the minimum number of decimal places needed.
Example
<?php
$a=44.234224;
$b=5.4320998;
$sum=$a+$b;
echo($a+$b);
?>
Output
49.6663238
6. Boolean
Boolean data type may contain two possibilities, either True or False.
Example
<?php
$a=true;
if(true)
Else
?>
Output
Statement is valid
bool(true)
Example
<?php
$empty= null;
var_dump($empty)
?>
Output
NULL
8. Strings
Strings are a collection of characters that can have any text within quotes. You may use
single or double quotes. Object and array are called compound data types, whereas
the other five lie in the category of simple data types.
In PHP, there is no limit with respect to the string length. Escape Character sequences
which contain backslashes are replaced with special characters.
Example
<?php
$a=Welcome to Cloudways;
echo $a;
?>
Output
Welcome to Cloudways
There are several statements in PHP that you can use to make decisions:
The if statement
The if...else statement
The if...elseif....else statement
The switch...case statement
The if Statement
The if statement is used to execute a block of code only if the specified condition evaluates
to true. This is the simplest PHP's conditional statements and can be written like:
if(condition){
// Code to be executed
}
The following example will output "Have a nice weekend!" if the current day is Friday:
Example
<?php
$d = date("D");
if($d == "Fri"){
echo "Have a nice weekend!";
}
?>
The following example will output "Have a nice weekend!" if the current day is Friday,
otherwise it will output "Have a nice day!"
Example
Run this code
<?php
$d = date("D");
if($d == "Fri"){
echo "Have a nice weekend!";
} else{
echo "Have a nice day!";
}
?>
The following example will output "Have a nice weekend!" if the current day is Friday, and
"Have a nice Sunday!" if the current day is Sunday, otherwise it will output "Have a nice
day!"
Example
<?php
$d = date("D");
if($d == "Fri"){
echo "Have a nice weekend!";
} elseif($d == "Sun"){
echo "Have a nice Sunday!";
} else{
echo "Have a nice day!";
}
?>
switch(n){
case label1:
// Code to be executed if n=label1
break;
case label2:
// Code to be executed if n=label2
break;
...
default:
// Code to be executed if n is different from all labels
}
Consider the following example, which display a different message for each day.
Example
<?php
$today = date("D");
switch($today){
case "Mon":
echo "Today is Monday. Clean your house.";
break;
case "Tue":
echo "Today is Tuesday. Buy some food.";
break;
case "Wed":
echo "Today is Wednesday. Visit a doctor.";
break;
case "Thu":
echo "Today is Thursday. Repair your car.";
break;
case "Fri":
echo "Today is Friday. Party tonight.";
break;
case "Sat":
echo "Today is Saturday. Its movie time.";
break;
case "Sun":
echo "Today is Sunday. Do some rest.";
break;
default:
echo "No information available for that day.";
break;
}
?>
The switch-case statement differs from the if-elseif-else statement in one important way.
The switch statement executes line by line (i.e. statement by statement) and once PHP finds
a case statement that evaluates to true, it's not only executes the code corresponding to that
case statement, but also executes all the subsequent casestatements till the end of
the switch block automatically.
To prevent this add a break statement to the end of each case block. The breakstatement
tells PHP to break out of the switch-case statement block once it executes the code
associated with the first true case.
Q.5. How many types of loop use in PHP? Explain each in detail.?
If the test expression is a true then code block will be executed. After the code
has executed the test expression would again be evaluated and the loop would
continue until the test expression is found to be false in php.
Syntax :
while(condition)
statement(s);
increment/decrements;
1.Condition :- the first step of for loop is condition , if condition is true then
body part is execute .otherwise body part is not execute in php .
2.statements :- this part is body part. all three step are execute then body
part is executed .in this part display any type of message in web page using
php.
Example :-
<?php
int $i;
while($i<3)
echo i am programmer;
$i++;
?>
Output:
i am programmer
i am programmer
i am programmer
do while loop is different loop of the for loop and while loop because , the do
while loop in php language checks its condition at the bottom of the loop.
in php language ,A do while loop is similar to a while loop, except that a do
while loop is guaranteed to execute at least one time.
Syntax :
do
statement(s);
increment/decrements;
}while( condition );
Example :
<?php
int $i;
do
echo i am programmer;
$i++;
}while( $i<3 )
?>
Output:
i am programmer
i am programmer
i am programmer
(3)PHP for Loop : In php language, A for loop statement is a repetition control
structure that allows you to efficiently write a loop that needs to execute a
specific number of times. A for loop example and syntax are as bellow.
Syntax :
statement(s);
4.statements :- this part is body part. all three step are execute then body
part is executed .in this part display any type of message in web page.
Example :
<?php
int $i;
echo i am programmer;
?>
Output:
i am programmer
i am programmer
i am programmer
(4)PHP foreach Loop :The foreach looping statement is used to loop through
a arrays. For each pass the value of the current array element is assigned to
$value and the array pointer is moved by one and in the next pass next element
would be processed in php.
Syntax :
Statement;
1. Array :- array is store different value like 1,2,3,4,, etc type of unindex
value . then one by one are display on web page.
2. Value :- value type variable is store one by one value of array and then after
one by one value is display in web page.
3. Statement :- statement means execute block . his part is body part. all
three step are execute then body part is executed .in this part display any type
of message or value in php.
Example :
<?php
?>
Output:
Value is 10
Value is 20
Value is 30
Value is 40
Value is 50
Many high-profile open-source projects ceased to support PHP 4 in new code as of February 5,
2008, because of the GoPHP5 initiative,[26]provided by a consortium of PHP developers promoting
the transition from PHP 4 to PHP 5.[27][28]
Over time, PHP interpreters became available on most existing 32-bit and 64-bit operating systems,
either by building them from the PHP source code, or by using pre-built binaries. [29] For the PHP
versions 5.3 and 5.4, the only available Microsoft Windows binary distributions were 32-
bit x86 builds,[30][31] requiring Windows 32-bit compatibility mode while using Internet Information
Services (IIS) on a 64-bit Windows platform. PHP version 5.5 made the 64-bit x86-64 builds
available for Microsoft Windows.
Ans 8 (d) Flat File - A flat file database is a database which is stored on its host computer system
as an ordinary unstructured file called a "flat file". To access the structure of the data and manipulate
it, the file must be read in its entirety into the computer's memory. Upon completion of the database
operations, the file is again written out in its entirety to the host's file system. In this stored mode the
database is said to be "flat", meaning that it has no structure for indexing and there are usually no
structural relationships between the records. A flat file can be a plain text file or a binary file.
The term has generally implied a small, simple database. As computer memory has become
cheaper, more sophisticated databases can now be entirely held in memory for faster access. These
newer databases would not generally be referred to as flat-file databases. Flat files are used not only
as data storage tools in DB and CMS systems, but also as data transfer tools to remote servers (in
which case they become known as information streams).
In recent years, this latter implementation has been replaced with XML files, which not only contain
but also describe the data. Those still using flat files to transfer information are mainframes
employing specific procedures which are too expensive to modify.
One criticism often raised against the XML format as a way to perform mass data transfer operations
is that file size is significantly larger than that of flat files, which is generally reduced to the bare
minimum. The solution to this problem consists in XML file compression (a solution that applies
equally well to flat files), which has nowadays gained EXI standards (i.e., Efficient XML Interchange,
which is often used by mobile devices).