Building Web Applications in PHP
Building Web Applications in PHP
Visit the Shop for Amazing and very useful software and tools! Dismiss
books & Digital learning International Degrees Learning New Posts Free IT Dumps
Free Software E-Hacking Tools Shop Cart Checkout My account
How to setup Jupyter Notebook In python How to create Arrays in python using NumPy
ITEXAMTOOLS
Cisco Press Publications | Online
Degrees | Pearson e-Books | Q&A and
FREE downloads IT Learning Lessons
Contact Us
DISCLOSURE
ITExamtools.com Is
learner supported &
https://itexamtools.com/building-web-applications-in-php/ 1/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
How a web browser interacts with a web server, Top 25 online courses in
India
request/response cycle, including GET/POST/Redirect.
an introductory understanding of Hypertext Markup Top 25 online courses in
Oman
Language (HTML), as well as the basic syntax and data
Top 25 online courses in
structures of the PHP language, variables, logic, iteration, Qatar
arrays, error handling, and superglobal variables, among
Top 25 online courses in
other elements. An introduction to Cascading Style South Africa
Sheets (CSS) will allow you to style markup for web Top 25 online courses in
pages, & the skills and knowledge to install and use an Malaysia
integrated PHP/MySQL environment like XAMPP or Top 25 online courses in
MAMP. Australia
https://itexamtools.com/building-web-applications-in-php/ 2/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
Media error: Format(s) not
About variables—what they are, why you need to use supported or source(s) not
found
them, and how to use them Download File:
data:image/gif;base64,R0lG
How to define and access variables ODdhAQABAPAAAP///wAA
ACwAAAAAAQABAEACAk
QBADs=
About data types Download File:
data:image/gif;base64,R0lG
ODdhAQABAPAAAP///wAA
About some of the more commonly used operators ACwAAAAAAQABAEACAk
QBADs=
How to use operators to create expressions
Master Data
Variables Science Career
Skills
A variable is a special container that you can define,
which will then “hold” a value, such as a number, string,
object, array, or a Boolean. Variables are fundamental to
programming. Without variables, you would be forced to
hard-code each specific value used in your scripts. The
following hard-coded statement adds two numbers
Top paying Jobs
together and prints the result, which solves a simple All over the World
mathematics problem:
The best paying jobs in
echo (2 + 4); New Zealand
The best paying jobs in
However, this snippet of code is useful only for people Thailand
who specifically want to know the sum of 2 and 4. To get
The best paying jobs in
past this limitation, you could write a script for finding the Nigeria
sum of another set of numbers, say 3 and 5. However, The best paying jobs in
this approach to programming is clearly absurd, and this Vietnam
specific values the variables represent. Values will be The best paying jobs in
South Africa
given to the variables when the script is run, possibly
through user input, through a database query, or from the The best paying jobs in
the Philippines
result of another action earlier in the script. In other
The best paying jobs in
words, variables should be used whenever the data in
Singapore
https://itexamtools.com/building-web-applications-in-php/ 3/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
your script is liable to change—either during the lifetime The best-paying jobs in
Canada
of the script, or when it is passed to another script for
later use. The best-paying jobs in
Pakistan
$a;
$a_longish_variable_name;
$2453;
$sleepyZZZZ;
Free Learning
By the Way Resources
https://itexamtools.com/building-web-applications-in-php/ 4/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
previous fragment of code are not part of the variable Free chapters from Sams
Publishing
names, but are used to end the statement that declares
the variable as “alive and kicking,” if you will. To declare a SQL Queries:
variable, you need only include it in your script. When you Summarizing Data Results
from a Query in SQL
declare a variable, you usually assign a value to it in the
same statement, as shown here: Understanding How Java
Programs Work
$num1 = 8;
Understanding Dynamic
$num2 = 23; Websites and HTML5
Applications
The preceding lines declare two variables and use the
assignment operator (=) to assign values to them. You
will learn about assignment in more detail in the
“Operators and Expressions” section later in this chapter. Deal of the DAY –
Official IT Books
After you assign values to your variables, you can treat
them exactly as if they were the values themselves. In
other words
echo $num1;
Popular Recent
is equivalent to Comments Tags
echo 8;
Udemy Budget
Affordable
as long as $num1 is assigned a value of 8.
Discount sale
2021
Globals and Superglobals
Master of Applied
In addition to the rules for naming variables, there are
Data Science
rules regarding the availability of variables. In general, the
assigned value of a variable is present only within the
function or script where it resides. For example, if you Modeling
have scriptA.php that holds a variable called $name with Techniques in
a value of joe, and you want to create scriptB.php that Predictive
Analytics:
also uses a $name variable, you can assign to that
Analytics and Data
second $name variable a value of jane without affecting Science
the variable in scriptA.php. The value of
https://itexamtools.com/building-web-applications-in-php/ 5/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
the $name variable is local to each script, and the IP Routing in the
LAN
assigned values are independent of each other.
https://itexamtools.com/building-web-applications-in-php/ 7/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
Resource types are often returned by functions that deal Cisco Career
with external applications or files. For example, you will Certifications
see references to “the MySQL resource ID” in Chapter Cisco Collaboration
Exams
18, “Interacting with MySQL Using PHP.” The NULL type
CCNP/CCIE
is reserved for variables that have been declared, but no
350-
value has been assigned to them. 801[CLCOR]
Q&A and More
PHP has several functions available to test the validity of
CCNP/Speciali
a particular type of variable—one for each type, in fact. st 300-810
The is_* family of functions, such as is_bool(), tests [CLICA] Q&A
and more
whether a given value is a Boolean. Listing 5.1 assigns
different data types to a single variable and then tests the 300-815
[CLACCM]
variable with the appropriate is_* function. The comments
Q&A and more
in the code show you where the script is in the process.
CCNP 300-820
[CLCEI] Q&A
By the Way
and more
https://itexamtools.com/building-web-applications-in-php/ 8/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
You can read more about calling functions in Chapter 7. CCNP 300-835
[CLAUTO] Q&A
Listing 5.1. Testing the Type of a Variable and more
1: <?php
Cisco CyberOps
2: $testing; // declare without assigning
3: echo "is null? ".is_null($testing); // checks if n
Exams
4: echo "<br/>"; CyberOps
5: $testing = 5; Associate 200-
6: echo "is an integer? ".is_int($testing); // checks 201 CBROPS
7: echo "<br/>";
Q&A and more
8: $testing = "five";
9: echo "is a string? ".is_string($testing); // check CyberOps
10: echo "<br/>"; Professional
11: $testing = 5.024; 350-201
12: echo "is a double? ".is_double($testing); // check
[CBRCOR]
13: echo "<br/>";
14: $testing = true;
Q&A and more
15: echo "is boolean? ".is_bool($testing); // checks i CyberOps
16: echo "<br/>"; Professional
17: $testing = array('apple', 'orange', 'pear');
300-215
18: echo "is an array? ".is_array($testing); // checks
19: echo "<br/>";
[CBRFIR] Q&A
20: echo "is numeric? ".is_numeric($testing); // check and more
21: echo "<br/>";
22: echo "is a resource? ".is_resource($testing); // c Cisco Data Center
23: echo "<br/>"; Exams
24: echo "is an array? ".is_array($testing); // checks
CCNP Data
25: echo "<br/>";
26: ?>
Center 350-601
[DCCOR] Cisco
Certified
Specialist
Put these lines into a text file called testtype.php, and
place this file in your web server document root. When CCNP Data
Center 300-610
you access this script through your web browser, it [DCID] Cisco
produces the following output: Certified
Specialist. Q&A
is null? 1 and more
is an integer? 1
is a string? 1 CCNP Data
is a double? 1 Center 300-615
is boolean? 1 [DCIT] Cisco
is an array? 1 Certified
is numeric?
Specialist
is a resource?
is an array? 1 CCNP Data
Center 300-620
[DCACI]Data
https://itexamtools.com/building-web-applications-in-php/ 9/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
https://itexamtools.com/building-web-applications-in-php/ 10/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
to code Deep
By the Way but not Learning
sure Engineer
Per the PHP Manual, “double” is returned in case of a Jobs
where to
float, and not simply “float”. Your eyes are not deceiving
start?
you.
One of
In each case, we use the appropriate is_* function to the most
confirm the new data type and to print the value of the common
7 skills
variable $undecided to the browser using echo. When we questions
employer
convert the string “3.14” to an integer in line 6, any we hear s of the
information beyond the decimal point is lost forever. is, “Which future will
be
That’s why $undecided contains 3 after we change it programm
looking
back to a double in line 8. Finally, in line 10, we ing for
convert $undecided to a Boolean. Any number other language
than 0 becomes true when converted to a Boolean. When is Futurepro
https://itexamtools.com/building-web-applications-in-php/ 11/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
https://itexamtools.com/building-web-applications-in-php/ 12/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
Listing 5.3 never actually changes the type of logic, the AI can
https://itexamtools.com/building-web-applications-in-php/ 13/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
Thinking CompTIA
The generic term number is used here to mean integers
about A+
and floats. If the user input is in float form, and the strings Complete
learning
added together were “3.14cm” and “4.12cm”, the answer overview
to code
provided would be 7.26.
but not This guide
During the casting of a string into an integer or float, PHP sure helps you
will ignore any non-numeric characters. The string will be where to get a
truncated, and any characters from the location of the first start? better
non-numeric character onward are ignored. So, One of grasp of
https://itexamtools.com/building-web-applications-in-php/ 14/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
https://itexamtools.com/building-web-applications-in-php/ 16/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
https://itexamtools.com/building-web-applications-in-php/ 17/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
$name = "jimbo";
Data
The variable $name now contains the string “jimbo”. This science
construct is also an expression. Although it might seem at interview
preparati
first glance that the assignment operator simply changes on: How
the variable $name without producing a value, in fact, a to answer
statement that uses the assignment operator always top
questions
resolves to a copy of the value of the right operand. Thus
When it
echo $name = "jimbo";
comes to
prints the string “jimbo” to the browser while it also interview
assigns the value “jimbo” to the $name variable. preparatio
n, for data
Arithmetic Operators science
technical
The arithmetic operators do exactly what you would
savviness
expect—they perform arithmetic operations. Table 5.2
and
lists these operators along with examples of their usage
communic
and results.
ation skills
Table 5.2. Arithmetic Operators are of
equal
Operator Name Example Sample Result
importanc
+ Addition 10+3 13 e.
− Subtraction 10−3 7
* Multiplication 10*3 30
Posts
% Modulus 10%3 1
https://itexamtools.com/building-web-applications-in-php/ 18/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
The addition operator adds the right-side operand to the CISCO Featur
ed
left-side operand. The subtraction operator subtracts the
right-side operand from the left-side operand. The
division operator divides the left-side operand by the
right-side operand. The multiplication operator multiplies
CCNA How
the left-side operand by the right-side operand. The
200-301 HADOO
modulus operator returns the remainder of the left-side
(Cisco P is
operand divided by the right-side operand.
Certifie useful
d to data
The Concatenation Operator Networ scientis
k ts
The concatenation operator is represented by a single Associ
period (.). Treating both operands as strings, this operator ate) – Hadoop
appends the right-side operand to the left-side operand. Comple allows the
So te users to
store all
"hello"." world"
CCNA forms of
200-301 data, and
returns
(Cisco provides
"hello world" Certified massive
Network storage
Note that the resulting space between the words occurs
Associate for any
because there is a leading space in the second operand
)– kind of
(” world” instead of “world”). The concatenation operator
Complete data.…
literally smashes together two strings without adding any
The Cisco
padding. So, if you tried to concatenate two strings
Certified
without leading or trailing spaces, such as
Network
"hello"."world" Associate
(CCNA How to
you would get this as your result:
200-301) whizz
exam is a Your Next
"helloworld"
Remote
120- Interview
Regardless of the data types of the operands used with minute…
the concatenation operator, they are treated as strings, Remote
and the result will always be of the string type. You will What’s interviews
new in
https://itexamtools.com/building-web-applications-in-php/ 19/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
$x = 4; How to Building
$x += 4; // $x now equals 8 whizz Web
Your Next Applicati
Each arithmetic operator, as well as the concatenation Remote ons in
Interview PHP
operator, also has a corresponding combination
assignment operator. Table 5.3 lists these new operators Remote Learn
and shows an example of their usage. interviews How a
are now web
https://itexamtools.com/building-web-applications-in-php/ 20/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
https://itexamtools.com/building-web-applications-in-php/ 22/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
than 4. university
in the
IP
Comparison Operators Routing U.S. and
in the join the
Comparison operators perform comparative tests using LAN next
their operands and return the Boolean value true if the generatio
Almost all
test is successful or false if the test fails. This type of n of data
enterprise
expression is useful when using control structures in your scientists.
networks
scripts, such as if and while statements. This book Completel
use
covers if and while statements in Chapter 6, “Flow y online.
VLANs.
Control Functions in PHP.”
To route
For example, to test whether the value contained in $x is IP
smaller than 5, you can use the less-than operator as part packets in
of your expression: and out of
those
$x < 5 CCNP
VLANs, Enterpris
If $x contains the value 3, this expression will have the some e
devices Advanced
value true. If $x contains 7, the expression resolves
Routing
to false. (either
ENARSI
https://itexamtools.com/building-web-applications-in-php/ 23/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
IP Enterprise
== Equivalence Left is $x == 5 false
address in Advanced
equivalent
to right each Routing
subnet ENARSI
!= Non- Left is not $x != 5 true
equivalence equivalent and have 300-410
to right a Official
https://itexamtools.com/building-web-applications-in-php/ 24/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
true || false
https://itexamtools.com/building-web-applications-in-php/ 26/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
Operator Precedence
When you use an operator within an expression, the PHP
engine usually reads your expression from left to right.
For complex expressions that use more than one
operator, though, the PHP engine could be led astray
without some guidance. First, consider a simple case:
4 + 5
4 + 5 * 2
(4 + 5) * 2
https://itexamtools.com/building-web-applications-in-php/ 27/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
++, –, (cast)
/, *, %
+, –
==, ===, !=
&&
||
and
xor
or
$x and $y || $z
https://itexamtools.com/building-web-applications-in-php/ 28/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
Html
https://itexamtools.com/building-web-applications-in-php/ 29/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
https://itexamtools.com/building-web-applications-in-php/ 30/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
University of Michigan
Enrollment options
you can Enroll this course for FREE and can learn totally
free for next 7 days and if you feel it is worth to enhance
your knowledge and career, you can go further for getting
the certification.
Shareable Certificates
https://itexamtools.com/building-web-applications-in-php/ 31/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
Practice Quizzes
PHP Constants
Variables offer a flexible way of storing data because you
can change their values and the type of data they store at
any time during the execution of your scripts. However, if
you want to work with a value that must remain
unchanged throughout your script’s execution, you can
define and use a constant. You must use PHP’s built-
in define() function to create a constant, which
subsequently cannot be changed unless you
specifically define() it again. To use the define() function,
place the name of the constant and the value you want to
give it, within parentheses and separated by a comma:
define("YOUR_CONSTANT_NAME", 42);
https://itexamtools.com/building-web-applications-in-php/ 32/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
Put these few lines into a text file called constant.php and
place this file in your web server document root. When
you access this script through your web browser, it
produces the following output:
echo the_year;
echo ThE_YeAr;
echo THE_YEAR;
https://itexamtools.com/building-web-applications-in-php/ 33/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
Predefined Constants
PHP automatically provides some built-in constants for
you. For example, the constant __FILE__ returns the
name of the file that the PHP engine is currently reading.
The constant __LINE__ returns the current line number of
the file. These constants are useful for generating error
messages. You can also find out which version of PHP is
interpreting the script with the PHP_VERSION constant.
This constant can be useful if you need version
information included in script output when sending a bug
report.
Summary
This chapter covered some of the basic features of the
PHP language. You learned about variables and how to
assign values to them using the assignment operator, as
well as received an introduction to the scope of variables
and built-in superglobals. You got an introduction to
operators and learned how to combine some of the most
common of these into expressions. Finally, you learned
how to define and access constants.
https://itexamtools.com/building-web-applications-in-php/ 34/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
Q&A
Q. Why is it useful to know the type of data that a
variable holds?
Workshop
https://itexamtools.com/building-web-applications-in-php/ 35/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
Quiz
1. Which of the following variable names are not valid?
$a_value_submitted_by_a_user $666666xyz
$xyz666666 $_____counter_____ $the first $file-name
Answers
1. The variable name $666666xyz is not valid because it
does not begin with a letter or an underscore
character. The variable name $the first is not valid
because it contains a space. $file-name is also invalid
because it contains a nonalphanumeric character (-).
https://itexamtools.com/building-web-applications-in-php/ 36/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
Activities
1. Create a script that contains at least five different
variables. Populate them with values of different data
types and use the gettype() function to print each type
to the browser.
https://itexamtools.com/building-web-applications-in-php/ 37/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
https://itexamtools.com/building-web-applications-in-php/ 38/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
positions are
available),…
Master of CCNP
Applied Data Enterprise
Science Advanced
Routing
University of ENARSI
300-410
Michigan Official Cert
Guide
Online
Master CCNP
Degree Enterprise
Learn from Advanced
the #1 public Routing
research ENARSI
university in 300-410
the U.S. and Official Cert
join the next Guide.
generation Published
of data Mar 19,
scientists. 2020 by
Completely Cisco Press.
online. Part of the
Official Cert
Guide
series.
Leave a Reply
Comment
https://itexamtools.com/building-web-applications-in-php/ 39/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
Post Comment
This site uses Akismet to reduce spam. Learn how your comment
data is processed.
A Hands-On Guide
to Splunk
Enterprise Security Dev VCP
Ops 6- Sec
for DCV urity
Apache Kafka For VM Offic +
war ial SY0
Absolute e Cert -401
Beginners Adm Guid
inistr e
ator
Hadoop Developer s
Course with
MapReduce and
Java
Google BigQuery
& PostgreSQL :
Big Query for Data
Analysis
https://itexamtools.com/building-web-applications-in-php/ 40/41
7/1/2021 Building Web Applications in PHP - ITEXAMTOOLS
Learn Ethical
Hacking -CEHv10
from scratch
© 2021 ITEXAMTOOLS. All Rights Reserved. || The TREAD MARKS used in the website are the tread marks of the respective
site owners. ||
Sitemap Disclosure Privacy Policy TOS
https://itexamtools.com/building-web-applications-in-php/ 41/41