Send a link to your students to track their progress
95 Terms
1
New cards
"PHP: Hypertext Preprocessor
PHP is an acronym for
2
New cards
PHP
* widely-used, open-source scripting language * scripts are executed on the server * free to download and use
3
New cards
text, HTML, CSS, JavaScript, and PHP code
PHP files can contain 5
4
New cards
server
HTML
PHP code is executed on the ____, and the result is returned to the browser as plain__ ___
5
New cards
.php
PHP files have extension
6
New cards
PHP can generate dynamic page content
PHP can create, open, read, write, delete, and close files on the server
PHP can collect form data
PHP can send and receive cookies
PHP can add, delete, modify data in your database
PHP can be used to control user-access
PHP can encrypt data
What can PHP Do?
7
New cards
1. runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.) 2. compatible with almost all servers used today (Apache, IIS, etc.) 3. supports a wide range of databases 4. is free. Download it from the official PHP resource: www.php.net 5. is easy to learn and runs efficiently on the server side
Why PHP?
8
New cards
HTML
A PHP scripting block always starts with __ __and ends with___.
A PHP scripting block can be placed anywhere in the document.
On servers with shorthand support enabled you can start a scripting block with .
For maximum compatibility, we recommend that you use the standard form ( A PHP file normally contains ____ tags, just like an HTML file, and some PHP scripting code.
9
New cards
echo
PHP has a built-in "_____" function, which is used to output text.
In actuality, it's **not a function; it's a language construct**.
As such, it **does not require parentheses.**
10
New cards
semicolon
Each code line in PHP must end with a ____. The__ ___ is a separator and is used to distinguish one set of instructions from another.
11
New cards
echo and print.
There are two basic statements to output text with PHP:
12
New cards
comment
\
In PHP code, a ____ is a line that is not executed as part of the program.
You can use _____ to communicate to others so they understand what you're doing, or as a reminder to yourself of what you did.
13
New cards
Multi-line
/\* \*/
_______ comments are used for composing comments that take more than a single line.
A _______ comment begins with ____ and ends with ____.
14
New cards
Variables
dollar sign ($)
___ __are used as "containers" in which we store information.__
__A PHP var_____able starts with a__ __*, which is followed by the name of the*__ _______.
15
New cards
1. A variable name must start with a letter or an underscore 2. A variable name cannot start with a number 3. A variable name can only contain alpha-numeric characters and underscores (A- z, 0-9, and _ ) 4. Variable names are case-sensitive ($name and $NAME would be two different variables)
The arrays in the______ can be both numeric and associative.
The dimension of an array indicates the number of indices you would need to select an element.
For a ______array, you need two indices to select an element
For a _______ array, you need three indices to select an element
45
New cards
loops
Often when you write code, you want the same block of code to run over and over again in a row. Instead of adding several almost equal lines in a script we can use _______ to perform a task like this.
46
New cards
while loop
do...while loop
for loop
foreach loop
4 looping statements:
47
New cards
while loop
Syntax:
$i = 1;
while ($i
The_____ executes a block of code as long as the specified condition is true.
48
New cards
do...while loop
$i=5;
do {
echo "The number is ". $i . " ";
$i++;
} while ($i
The ______ will always execute the block of code once, check the condition, and repeat the loop as long as the specified condition is true.
49
New cards
for loop
\
for ($a=0;$a
The ___ is used when you know in advance how many times the script should run.
50
New cards
init:
condition:
increment/decrement:
THE FOR LOOP 3 Parameters:
\ ____Initialize the loop counter value
____Evaluates each time the loop is iterated, continuing if evaluates to true, and ending if it evaluates to false
____ Increases the loop counter value
51
New cards
foreach loop
\
$names = array("John", "David","Amy"); foreach($names as $name){
echo $name. " "; }
?> /\* Output: John David Amy \*/
The _____ works only on arrays, and is used to loop through each key/value pair in an array.
52
New cards
continue statement
When used within a looping structure, the ______ allows for skipping over what remains of the current loop iteration. It then continues the execution at the condition evaluation and moves on to the beginning of the next iteration.
53
New cards
include and require statements
The ___ __&__ _____allow for the insertion of the content of one PHP file into another PHP file, before the server executes it.
54
New cards
require statement
include statement
The _____ is identical to include, the exception being that, **upon failure, it produces a fatal error.**
When a file is included using the______, but PHP is **unable to find it, the script continues to execute.**
In the case of require, the script will cease execution and produce an error.
55
New cards
require
include
Use ____ when the file is required for the application to run.
Use ____ when the file is not required. The application should continue, even when the file is not found.
56
New cards
function
\
function functionName() { //code to be executed } ?>
A _____ is a block of statements that can be used repeatedly in a program.
A _____ will not execute immediately when a page load. It will be executed by a call to the _____.
57
New cards
arguments
Information can be passed to functions through ______, which are like variables.
______ are specified after the function name, and within the parentheses.
You can add as many _____ as you want, as long as they are separated with commas.
58
New cards
parameters
argument
When you define a function, the variables that represent the values that will be passed to it for processing are called _______.
However, when you use a function, the value you pass to it is called an ____.
59
New cards
return statement
A function can return a value using the______. the______ stops the function's execution, and sends the value back to the calling code.
returns the ip add where the user is viewing the current page
68
New cards
\[‘REMOTE_HOST‘\]
returns the host name where the user is viewing the current page
69
New cards
\[‘REMOTE_PORT‘\]
returns the port being used on the user’s machine to communicate w/ the web server
70
New cards
\[‘SCRIPT_FILENAME‘\]
returns the absolute path name of the currently executing script
71
New cards
\[‘SERVER_PORT‘\]
returns the port on the server machine being used by the web server for communication (such as 80)
72
New cards
\[‘SCRIPT_NAME‘\]
returns the path of the current script
73
New cards
\[‘SCRIPT_URI‘\]
returns the URI of the current page
74
New cards
$_GET
$_POST
The purpose of the PHP superglobals __ __and__ ____ is to collect data that has been entered into a form.
75
New cards
PHP scripts
The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your______
76
New cards
action
The ______ attribute specifies that when the form is submitted, the data is sent to a PHP file named first.php.
77
New cards
$_POST
mwthod = “post'“
The built-in ___ __function is used to collect values from a form sent with__ ____.
Information sent from a form with the ___ __method is invisible to others and has no limits on the amount of information to send.__
___ is the preferred method for sending form data.
when we have an HTML form with the action attribute set to our PHP file, we can access the posted form data using the _____ associative array.
The _____ superglobal array holds key/value pairs.
In the pairs, keys are the names of the form controls and values are the input data entered by the user.
78
New cards
$_GET
mwthod = “get'“
The built-in____ function is used to collect values from a form sent within____.
Information sent from a form with the in____ method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send.
79
New cards
fopen()
The ___ __function creates or opens a file. If you use__ __ with a file that does not exist, the file will be created, given that the file has been opened for writing (w) or appending (a).
80
New cards
1. r 2. w 3. a 4. x 5. r+ 6. w+ 7. a+ 8. x+
Manipulating Files 8 command :
81
New cards
r
Opens file for read only.
82
New cards
w
Opens file for write only. Erases the contents of the file or creates a new file if it doesn't exist.
83
New cards
a
Opens file for write only.
84
New cards
x
Creates new file for write only.
85
New cards
r+
Opens file for read/write.
86
New cards
w+
Opens file for read/write. Erases the contents of the file or creates a new file if it doesn't exist.
87
New cards
a+
Opens file for read/write. Creates a new file if the file doesn't exist
88
New cards
x+
Creates new file for read/write.
89
New cards
fwrite()
string
When writing to a file, use the___ __function.__
__The first parameter of__ __*is the file to write to; the second parameter is the*__ _____ to be written.
90
New cards
fclose()
\\n
The______ function closes an open file and returns TRUE on success or FALSE on failure. It's a good practice to close all files after you have finished working with them.
__The__ _ symbol is used when writing new lines.
91
New cards
a
When appending to a file using the ___ mode, the file pointer is placed at the end of the file, ensuring that all new data is added at the end of the file.
92
New cards
isset()
The ____ function determined whether the form had been submitted, as well as whether the text contained a value. We did not specify an action attribute for the form, so it will submit to itself.
93
New cards
file()
The ____function reads the entire file into an array. Each element within the array corresponds to a line in the file: