Intro to PHP Flashcards
PHP: ______.
“PHP: Hypertext Preprocessor,” is a server language. This means that it executes code on the server then sends the results to the browser primarily as html content.
PHP manages __________ content, communicates with _____________, tracks user sessions, sends _______, read/write ________, implements __________, and ________ __________.
PHP manages dynamic content, communicates with databases, tracks user sessions, sends email, read/writes files, implements security, and processes forms.
A PHP block must begin with ______ and end with ______ .
a PHP block must begin with .
_______ PHP blocks can be used inside of one file.
Multiple PHP blocks can be used inside of one file.
Code (PHP) to output to page
echo(); //output to page
Code (PHP) that shows information about the server’s PHP installation
phpinfo(); //shows information about the server’s PHP installation
Code (PHP) to view all errors warnings and notices
error_reporting(E_ALL);
//view all errors warnings and notices
Different servers have different ________. If something doesn’t work, it might be a server ______ issue.
Different servers have different configurations. If something doesn’t work, it might be a server configuration issue.
PHP and HTML code _____ be used on the same page.
A simple way to use this technique effectively is to remember that _____ goes inside of PHP blocks and HTML _____t.
PHP and HTML code can be used on the same page.
A simple way to use this technique effectively is to remember that PHP goes inside of PHP blocks and HTML doesn’t.
To ouput html, use the _____ statement. _____(“html goes here”);
To ouput html, use the echo statement. echo(“html goes here”);
Variables start with a _
Variables start with a $
No variable ______ is required. You can just start using variables. e.g $someVar = 12
No variable declaration is required. You can just start using variables. e.g $someVar = 12
Concatenation uses a _____ NOT a ___ sign. e.g.
Concatenation uses a period NOT a plus sign.
Example:
$var1 = “I love”;
$var2 = “servers”;
echo($var1.$var2); //outputs “I loveservers”
Double quotes will _____ variables, and special characters, like \n or \t.
Single quotes will not and will ____ the literal string.
Double quotes will parse variables, and special characters, like \n or \t.
Single quotes will not and will output the literal string.
Example:
$name = “Joe”;
‘Hi I am $name’ //Hi I am $name
“Hi I am $name” //Hi I am Joe
Example of an if statement:
$test = 1;
if ($test == 1) {
echo (“we <b>passed</b> with a score of $test”); //note how you can embed a variable directly in a string
}
Arrays hold _____ _____ referenced by a ______ ______ .
Arrays hold multiple values referenced by a numerical index.
Example:
$myArray = array(“a”,”b”,”c”); //create an array
array_push($myArray,”d”); //add to end of array
array_pop($myArray) //removes and returns the last element of an array
count($myArray); //returns the array length
echo($myArray[0]); //prints out the first value in the array
Looping through a php array:
for ($i=0; $i
The indexes of Associative arrays are _____, not numbers.
The indexes of Associative arrays are strings, not numbers.
Example:
$myArray = array(“first” => “Wasim”, “last” => “Singh”);
$myArray[“middle”] = “Andy”; //add associative property and value
foreach loop:
foreach( $array as $value ) {
echo (“Value is $value <br></br>”);
}
Single-quoted strings aren’t _______, so whatever you’ve put in the string, that’s what will show up.
Double-quoted strings are _____ and any PHP variables in the string are _______.
Additionally, escaped characters like \n for newline and \t for tab are not evaluated in single-quoted strings, but are evaluated in double-quoted strings
Single-quoted strings aren’t parsed, so whatever you’ve put in the string, that’s what will show up.
Double-quoted strings are parsed and any PHP variables in the string are evaluated. Additionally, escaped characters like \n for newline and \t for tab are not evaluated in single-quoted strings, but are evaluated in double-quoted strings
We can pass information to a PHP script via the _ _ _ method or the _ _ _ _ method.
These methods are defined in an HTML form and the _ _ _ method adds variables at the end of the URL.
We can pass information to a PHP script via the GET method or the POST method.
These methods are defined in an HTML form and the GET method adds variables at the end of the URL.
PHP can access these GET and POST variables and values via the $_GET and $_POST associative arrays.
Using ___, the URL is formatted with _____-value pairs like so:
http://yourwebsite.com/form-processor.php?name1=value1&name2=value2&name3=value3
Using GET, the URL is formatted with name-value pairs like so:
http://yourwebsite.com/form-processor.php?name1=value1&name2=value2&name3=value3
Note the format of the variables and the question mark at the beginning to signify the beginning of the variables string. Also notice the ampersand that separates variable/value pairs. This is known as a URL encoded string.
The ____ method produces a long string that appears in your _______ logs, in the browser’s Location: box and is recognized by search engines
The GET method produces a long string that appears in your server logs, in the browser’s Location: box and is recognized by search engines
The ____ method is restricted to send up to a limited number of characters (based on the browser)
The GET method is restricted to send up to a limited number of characters (based on the browser)