Web-based Applications Exam 1 (IS 4460)
True
"$a++" is an example of a unary operator.
ID Selector
#NameOfID - the css will only impact certain a single element
Numeric Variable
$myage = 21;
String Variable
$myname = "ANDY";
How do you create a new object in PHP?
$object = new Class;
Store output ready to display later on.
$out = sprintf("The result is: $%.2f", 123.42 / 12); echo $out; sprintf function is used to:
Create an array PHP
$team = array('Bill', 'Mary, 'Mike');
String Literal
'Hello'
MySQL is:
- A DBMS to track data - Robust and Free - Has English-like commands
PHP objects
- Class - Instance - Properties - Methods - Encapsulation
Why should everyone learn coding?
- Coding is in high demand - Coding complements and reinforces other fundamental skills such as problem solving and teamwork - Coding drives innovation and entrepreneurship
Numeric Literal
73
HTML comments
<!-- ......... -->
Local Variables
Accessed within a function. They cannot be accessed from areas of the code outside of their scope, unless they are declared outside of a function.
APACHE Web Server
All these technologies (HTML, CSS, JS, PHP) need to be hosted by a web server.
FALSE (CSS does this)
Apache web server enables the styling of any HTML elements: color, border, spacing, etc.
The Period:
Appends strings in PHP
API
Application Programming Interface
PHP Comments:
Are the same as JAVA comments (// and /* .... */)
Compact
At times you may want to use ______, the inverse of extract, to create an array from variables and their values.
include_once "library.php"
Attempt to include a requested file, and if not found, program execution continues
../../
Go up two directories
True
HTTP is a communication standard governing the requests and responses that take place between the browser running on the end user's computer and the web server.
h
Hour of day, 12-hour, leading 0's
g
Hour of day, 12-hour, no 0's
H
Hour of day, 24-hour, leading 0's
G
Hour of day, 24-hour, no 0's
$timestamp = mktime(7, 11, 0, 5, 2, 2016);
How would you create a Unix timestamp for 7:11 a.m. on May 2, 2016?
database functionalities
IDEs provide the following except: - In-editor debugging - breakpoints - program testing - db functionality
Practice good ethical behavior
If TRUST is important to you in all of you relationships; if HONESTY and INTEGRITY are qualities you need to depend on, then you need to practice good ethical behavior in EVERYTHING you do, not just when it's convenient.
True
If you reference a variable, changing the value of the reference will change the original as well.
Parent
If you write a method in a subclass with the same name as one in its parent class, its statements will override those of the parent class. Sometimes this is not the behavior you want, and you need to access the parent's method.
2 - One size 4 and one size 8
In the following piece of code, how many columns will be created? <div class="container-fluid"> <div class="row"> <div class="col-sm-4"></div> <div class="col-sm-8"></div> </div> </div>
require_once "library.php"
Includes a requested file. Program will terminate if not found
Object (referred to as a method)
Incorporates one or more functions, and the data they use, into a single structure.
Passing by reference
Passing a reference to the variable, not the variable itself.
Absolute Class Path
Points to the same location in a file, regardless of working directory.
Function
Print is a ________ in PHP, meaning you'll need to declare it as such. print("WTF")
HTML Attribute
Provide additional information about HTML elements. Found inside the element tag such as title = "Google"
HTML5
Provides features for audio, video, replacing plug-ins with older HTML versions. Provides APIs and connectors to other applications.
str_repeat($string,#)
Repeat a string # of times
If you encounter a bug in one of the open source tools, how would you get it fixed?
Report it to either the company or community.
strrev()
Reverse a string
What is the meaning of scope in PHP?
Scope refers to which parts of a program can access a variable. For example, a variable of global scope can be accessed by all parts of a PHP program.
public, protected, private
Scopes of properties and methods
JS
Scripting access to all HTML elements. Works with CSS to provide dynamic changes on the webpage without needing to connect to the server each time.
s
Seconds, leading 0's
CSS Syntax
Selector (h1) { declaration(property: value); declaration(font-size: 12px); declaration(color: blue); }
commas
Selectors can be grouped with
Action (forms)
Sets the target file on the server receiving the form. This is where the form is sent to.
Ethical Beliefs:
Shape the way we live - What we do, what we make, and the world we create via choices
Why be ethical?
Since doing what is ethical at times comes at a personal cost. Ethical questions are an inescapable part of being human.
Literal
Single quotes are _________ in PHP
Extract
Sometimes it can be convenient to turn the key/value pairs from an array into PHP variables. One such time might be when you are processing the $_GET or $_POST variables sent to a PHP script by a form.
Method (forms)
Specifies the HTTP method to use (get or post)
Relative class path
Starts from the given working directory, avoiding the need to provide the full absolute path.
Continue
Stops processing current iteration, but will continue to the next iteration
Constant Literals
TRUE/FALSE
Explode ($temp = explode(' ', "This is a sentence") [0] => This [1] => is [2] => a [3] => sentence
Takes a string containing several items separated by a single character (or string) and places each into an array.
HTTP
The communication standard governing the requests and responses that are sent between the browser running on the user's computer and the web server.
CSS
The crucial companion to HTML, ensuring that the HTML text and embedded images are laid out consistently and in a manner appropriate for the user's screen.
True
The directions of operators processing (left to right or right to left) are called the operator's associativity.
What is the difference between foreach and each?
The foreach...as construct is already a loop, executing repeatedly until the array is exhausted or you explicitly break out of the loop.
True
The function printf controls the format of the output text to browser by letting programmers put special formatting characters in a string.
HTML Element
The opening and closing tags including the text in between.
False
The operators '+', '-','*' and '/' have the same precedence and would be processed in the order in which they are encountered. Example 1 + 2 * 3 − 4 * 5 is same as 2 - 4 * 5 * 3 + 1
literal
The simplest form of expression is a _____________.
Global
To access variables from a function in the main code, insert the word ______ in front of the variable assignment. _______ $name = "Andy"
elseif
To cater for many different logic possibilities in a PHP program, we use the __________ statement.
How can you cause an object to be initialized when you create it?
To cause an object to be initialized when you create it, you can call a piece of initializing code by creating a constructor method called __construct within the class, and place your code there.
file_exists()
To check if a file exist, you should best use the _________ command.
$object = new Class;
To create a new object in PHP, use the new keyword such as:
date($format, $timestamp); ((echo date("1 F jS, Y -g:ia", time( ));
To display the date, use the date function
What is the purpose of the explode function?
To extract sections from a string that are separated by an identifier, such as extracting words separated by spaces within a sentence.
How can you incorporate one PHP file within another?
To incorporate one file within another, you can use the include or require directives, or their safer variants, include_once and require_once.
TRUE
To select an element with id "demo" you can use the '#demo' term.
sprintf
To send the output from printf to a variable instead of a browser, what alternative function would you use?
Ethical People:
Try to answer the question of how to live by reflecting on difficult situations. They then act in a way that is true to who they are and what they believe.
False (include once will literally only include the file once, even if it's referenced again)
Usage of include_once as in Code-B is exactly the same as include in Code-A so using either one has the same effect (no difference).
Class Selector
Used to select any HTML element that has a class attribute. It is not unique.
associative
Using ______ arrays you can reference the items in an array by name rather than by a numeric value.
What is the main benefit of using a function?
Using functions avoids the need to copy or rewrite similar code sections many times over by combining sets of statements so that they can be called by a simple name.
True
Variable of global scope can be accessed by all parts of a PHP program.
Week Specifier
W - Week number of year (1-52)
What four components are needed to create a fully dynamic webpage?
Web server (Apache), server-side scripting language (PHP), database (MySQL), client-side scripting language (JS)
Unlink('file.txt');
What is a PHP command for deleting the file file.txt?
Decrease the loading time of program files
What is one of the benefits of using a function?
<a href="http://www.w3schools.com">W3Schools</a>
What is the correct HTML for creating a hyperlink?
printf("%'*7.5s", "Happy Birthday");
What printf statement could be used to take the input "Happy Birthday" and output the string "**Happy"?
What is the difference between accessing a variable by name and by reference?
When you reference a variable by name, such as by assigning its value to another variable or by passing its value to a function, its value is copied. The original does not change when the copy is changed. But if you reference a variable, only a pointer (or reference) to its value is used, so that a single value is referenced by more than one name. Changing the value of the reference will change the original as well.
exec
Which PHP function enables the running of system commands?
file_get_contents
Which PHP function is used to read in an entire file in one go, even from across the web?
$__FILES
Which PHP super global variable holds the details on uploaded files?
Limited access to web server (PHP has high access to web servers!)
Which below is NOT a characteristic of PHP? - Scripting Language - Limited access to web server - Integrates seamlessly with HTML - Flexible (many ways to write PHP)
<link rel="stylesheet" type="text/css" href="mystyle.css">
Which below is the correct HTML code for referring to an external style sheet called 'mystyle.css'? - <stylesheet>mystyle.css</stylesheet> - <link rel="stylesheet" type="text/css" href="mystyle.css"> - <style src="mystyle.css"> - <link method='post' action='page.php' />
Use the w+ file access mode with fopen to open a file in write and read mode, with the file truncated and the file pointer at the start.
Which file access mode would you use with fopen to open a file in write and read mode, with the file truncated and the file pointer at the start?
body {color: black;}
Which is the correct CSS syntax?
WAMP is an IDE
Which of the following about dynamic web is FALSE? - MySQL is a dbms - PHP is a server-scripting language - WAMP is an IDE - Apache web server is a web server
You can use either.
Which of the following tag styles is preferred in HTML5: <hr> or <hr />?
%f
Which printf conversion specifier would you use to display a floating-point number?
variable will be noted
With double quotes in PHP:
Encapsulation
Writing a class in such a way that only its methods can be used to manipulate its properties. This makes debugging easy because you only have to fix faulty code within a class.
$object->$property (would attempt to look up the value assigned to a variable named $property)
You can call a method like this
What is the purpose of the count function?
You can use the count function to count the number of elements in an array.
How can you create a multidimensional array?
You need to assign additional arrays to elements of the main array.
PHP Literal
a notation for a fixed value (string, integer, double, etc..). They are exactly what you will see on the page and in the code. They are the SIMPLEST form of expression.
Apache handles
a wide range of files, from images and Flash files to MP3 audio files, RSS feeds, and more.
Javascript was created to
offer dynamic control over the various elements within an HTML document. (Also asynchronous communication)
Use private when
outside code should not access this member and extending classes also should not inherit it.
Use protected when
outside code should not access this member but extending classes should inherit it.
fopen modes
r - read from beginning r+ - Read from beginning, allow writing w - Write from beginning and truncate w+ - Write from beginning, truncate, allow reading a - Append a+ - Append, allow read
Scope
refers to which parts of a program has access a particular variable.
Switch in PHP
switch ($page) { case "Home": echo "You selected home <br>" ; break; case "About": echo "You selected about <br>" break;
Functions
- Involve less typing - Reduce syntax and other programming errors - Decrease the loading time of program files - Decrease execution time, because each function is compiled only once, no matter how often you call it - Accept arguments and can therefore be used for general as well as specific cases
Date Parameters
- Number of Hour - Number of Minute - Number of Seconds - Number of month - Number of day - The year
Request and Response (Steps)
1. Enter address 2. browser looks up IP address (DNS) 3. Server issues request for the home page at website 4. Request crosses internet and arrives at web server. 5. Web server looks for web page on disk 6. Web server retrieves page and returns it to browser. 7. Local browser displays webpage
Integrate HTML with CSS
1. External Style Sheet 2. Internal Style sheet 3. Inline Style (HIGHEST PRIORITY)
Advantages of development servers
1. Quickly save and test on a local machine 2. Errors and security problems stay local until the site is public 3. Works independently 4. Easier for debugging and improvement
Error at $object->save(); (Only $name and $password are referenced variables in the User class.)
<?php $object = new User; print_r($object); echo "<br>"; $object->name = "Joe"; $object->password = "1234"; print_r($object); echo "<br>"; $object->save(); class User{ public $name, $password; function save_user(){ echo "Save User code goes here"; } } ?>
True
<?php echo "a: [" . TRUE . "]<br>"; echo "b: [" . FALSE . "]<br>"; ?> The underlying value for a and b as shown above example are 1 (for a) and 0 or NULL (for b) respectively.
Hyperlinks in HTML
<a href ="https://www.google.com"> Google </a>
Three major new elements introduced in HTML5
<audio>, <video>, and <canvas> also, <article>, <summary>, <footer>, and more
Form example
<form action='http://www.google.com" method='post'> First Name: <br> <input type="text" name="firstname"><br> Last Name: <br> <input type="text" name="lastname"><br> <input type="submit" value='OK'> </form>
Image tags HTML
<img src='./lorem.jpg'></img>
TRUE
<style> is the HTML tag used to define an INTERNAL style sheet
MYSQL
A DBMS to track user changes. Free and popular, robust and fast, english-like commands, connects to PHP easily.
Require or Prohibit
A class may ______ or _______ arguments. It may also allow them without explicitly requiring them.
Subclass (derived class)
A derived class from a superclass (main class). It inherits features (using inheritance) from the superclass that are commonly repeated.
TRUE
A development server is a way for a developer to test code and allow one to work independently with few dependencies from external components.
How is an object different from a function?
A function is a set of statements referenced by a name that can receive and return values. An object may contain zero or many functions (which are then called methods) as well as variables (which are called properties), all combined in a single unit.
flock
A function to queue requests to access a file until your program releases the lock.
Static Variables
A local variable (within a function) that always keeps its value
What is the difference between a numeric and an associative array?
A numeric array can be indexed numerically. An associative array uses alphanumeric identifiers to index elements.
PHP
A server-side scripting language with unlimited access to web server, integrates seamlessly with HTML, and is very flexible.
Constructors
A special function/method to initialize the object with initial data when the object is first created. It takes two parameters.
$this
A special variable which can be used to access the current object's properties.
Computer Network
A structure linking computers together for the purpose of sharing information and services
Array
A way to group objects of the same type
A
AM or PM
Server
Accepts requests from a client and attempts to reply to it by serving a requested web page.
What do the IP address 127.0.0.1 and the URL http://localhost have in common?
Both 127.0.0.1 and http://localhost are ways of referring to the local computer. When a WAMP or MAMP is properly configured, you can type either into a browser's address bar to call up the default page on the local server.
Break
Breaks completely out of loop
How many values can a function return?
By default, a function can return a single value. But by utilizing arrays, references, and global variables, it can return any number of values.
Public Members
Can be referenced anywhere, including by other classes and instances of the object.
Private Members
Can be referenced only by methods within the same class -- Not by subclasses.
Protected Members
Can be referenced only by the object's class methods and those of any subclass
A web server:
Can usually handle multiple simultaneous connections, and spends its time listening for an incoming connection.
CSS stands for
Cascading Style Sheets: Styling and layout rules applied to the elements in an HTML document.
Create user object from user class
Class User { public $name, $password; function save_user() { echo "Save user code goes here"; } } $ object = new User;
for($count=0; $count<20; $count++)
Complete the LOOP code below for counting from zero to 19.
$jobs = array("analyst", "engineer","researcher","intern");
Create a new array for the following jobs. analyst engineer researcher intern
The clone operator
Creates a new instance of the class and copies the property values from the original instance to the new instance.
Global Variables
Declared outside any function. Only accessed outside function unless we use the 'global' keyword inside the function.
Why is it better to use a program editor instead of a plain-text editor?
Dedicated program editors are smart and can highlight problems in your code before you even run it.
Syntax to define constants in PHP
Define("ROOT_LOC", "usr/local/www/")
%c
Display ASCII character for arg
%
Display a % character
%b
Display arg as a binary integer
%d
Display arg as a signed decimal integer
%s
Display arg as a string
%o
Display arg as an octal integer
%u
Display arg as an unsigned decimal
%X
Display arg in uppercase hexadecimal
%e
Display arg using scientific notation
print_r()
Displays information in PHP about a variable in a way that is readable to humans. E.x. array values will be presented in a format that shows keys and elements.
Var_dump
Displays structured information about variables/expressions including its type and value
foreach($jobs as $item){ echo $item.' '; }
Do a foreach loop to iterate through and echo each item in the array. Assume the name of the array is $jobs.
Instance
Each new object based on a class is called an ________ of that class
fgets
Easiest way to read form a text file
CSS
Enables the styling of any HTML elements. Allows a separation of structure and presentation: facilitates scalability.
Asynchronous Communication
Exchanging data between a client and server after a web page has loaded. (background)
Why is it a good idea to explicitly declare properties within a class?
Explicitly declaring properties within a class is unnecessary, as they will be implicitly declared upon first use. But it is considered good practice as it helps with code readability and debugging, and is especially useful to other people who may have to maintain your code.
Month Specifiers
F - Month name m - Month number (leading 0's) M - Month name (Three letter) n - Month Number (No 0's) t - Number of days (28-31)
What is the purpose of using an FTP program?
FTP stands for File Transfer Protocol. An FTP program is used to transfer files back and forth between a client and a server.
True
Following is a more compact and faster assignment method using the array keyword. $p1 = array("Copier", "Inkjet", "Laser", "Photo");
<form> </form>
Form Tags
!rename
Function to move or rename a file or directory.
!unlink
Function to remove a file from the filesystem
xor
Gives TRUE if 1 and only 1 of the inputs is true
Being Ethical:
Is a part of what defines us as human beings. We are rational, thinking, choosing creatures.
Why is a framework such as jQuery Mobile so important for developing modern websites and apps
It allows developers to concentrate on building the core functionality of a website or web app, passing on to the framework the task of making sure it always looks and runs its best, regardless of the platform, the dimensions of the screen, or the browser it's running on.
What is the main benefit of the array keyword?
It enables you to assign several values at the same time, without repeating the array name.
Name the main disadvantage of working on a remote web server.
It is necessary to FTP files to a remote server in order to update them, which can substantially increase development time if this action is carried out many times in a session.
Year Specifiers
L - Leap Year? y - Year (2 digit) Y - Year (4 digit)
MAMP
Mac, Apache, MySQL, PHP - Describe a fully functioning setup used for developing dynamic web pages.
Double Underscore
Method names beginning with a ______ _______ are reserved, and you should not create any of this form.
i
Minutes, leading 0's
False (A client is a node)
On a computer network, a client that provides information or a service is also known as a server.
Use public when
Outside code should access this member and extending classes should also inherit it.
ucfirst()
PHP function to Uppercase the first letter of a string.
str_to_lower()
PHP function to lowercase an entire string
False
PHP has no further development so it has only a one version. Thus there is hardly a need to check if a function is available in the PHP version that is being used.
What are the main differences between PHP and JS?
PHP runs on the server and JS runs on the client. PHP can communicate with the database to store and retrieve data, but it cannot alter the user's web page quickly and dynamically. JS has the opposite benefits and drawbacks.
Unix Timestamps
PHP uses standard .........., which are simply the number of seconds since the start of January 1, 1970.
MySQL manages
all the data
PHP handles
all the main work on the web server
a
am or pm
Functions in PHP ( { } )
are used to separate out sections of code that perform a particular task. Efficient reuse of code.
MAMP Quick Reference
browser > Web Server/Apache > PHP > MySQL > Response to browser
function_exists( )
checks to see if the "function name" exists in the working version of PHP.
What syntax would you use to create a subclass from an existing one?
class Subclass extends Parentclass ...
Day Specifiers
d D j l N S w z
%x
display arg in lowercase hexadecimal
Ternary Operator PHP
echo $fuel<=1 ? "Fill Tank Now" : "There is enough fuel"
For Loop PHP
for ($count=1; $count<=12; ++$count) { echo "$count time 12 is ".$count*12; echo "<br>";
PHP function to create array
function fix_names($n1, $n2, $n3) { $n1 = ucfirst(strtolower($n1); $n2 = ucfirst(strtolower($n2); $n3 = ucfirst(strtolower($n3); return array($n1, $n2, $n3) }
CSS and Javascript
look after web page presentation