Chapter 1 - Review
<?php PHP CODE HERE ?>
filename.php
For HTML5 <meta charset="utf-8">
激光, 這兩個字是甚麼意思. A page's encoding determines how bytes of data are converted graphically into meaningful language. A page's encoding is literally declared via the meta tag in the document header. A document's embedded encoding must match the explicitly declared encoding for the text to be interpreted properly.
UTF-8 has replaced ASCII as the most popular encoding on the internet. It represents every character in the Unicode character set (Unicode provides a unique number for every character, no matter what the platform, no matter what the program, no matter what the language :)
- echo
- a language construct that echoes passed parameters and does not return a value.
If you want to pass more than one parameter to echo, the parameters must not be enclosed
within parentheses.
echo('param1 ', 'param2 ','param3')
→ param1 param2 param3 - print()
- a language construct that outputs its parameter, always returns the value 1.
print('I want ice cream.')
→ I want ice cream. - printf()
- outputs a formatted string.
printf('a %s with %u wings.', 'bird', 2)
→ a bird with 2 wings.
- # comment spanning one line
- // another comment spanning one line
- /*and yet another
comment spanning multiple lines*/
All php variables begin with the $ followed by a letter or underscore then any combination of letters, numbers or underscores.
ALL OK $_aCoolVariable, $my_name, $John4521
NOT OK $24_hours, $cost-per-unit
Variable names are CASE-SENSITIVE. $Error!=$error
=
$color = "blue";
The variable $color is assigned the value "blue"
A string variable is created using the assignment operator and quotations.
$text = "Dog, as a devil deified, lived as a god."
- .
- The concatenation operator acts as glue between values.
$var = "make " . "peace"; - .=
- The concatenation assignment operator appends the value on the right of the equal sign to the end of the left side operand.
$var .= " not war;"
Constants are defined using the define() function. They cannot be overwritten and are by default case sensitive. To output a constant - it must not be in quotations. They only accept null or scalar values(ie. boolean,float, int, string).
define(NAME_OF_CONSTANT, "value of constant");
<?php $review = array( 1=>array( 'q'=>'What tags are used to surround PHP code?', 'a'=>"<p><b><?php</b> <em>PHP CODE HERE</em> <b>?></b></p>" ), 2=>array( 'q'=>'What extension should a PHP file have?', 'a'=>"<p>filename<b>.php</b></p>" ), 3=>array( 'q'=>'What does a page’s encoding refer to? What impact does the encoding have on the page?', 'a'=>"<p>For HTML5 <code>".htmlspecialchars('<meta charset="utf-8">')."</code></p> <p>激光, 這兩個字是甚麼意思. A page's encoding determines how bytes of data are converted graphically into meaningful language. A page's encoding is literally declared via the meta tag in the document header. A document's embedded encoding must match the explicitly declared encoding for the text to be interpreted properly.</p> <p>UTF-8 has replaced ASCII as the most popular encoding on the internet. It represents every character in the Unicode character set (Unicode provides a unique number for every character, no matter what the platform, no matter what the program, no matter what the language :)</p>" ), 4=>array( 'q'=>'What PHP functions, or language constructs, can you use to send data to the Web browser?', 'a'=>" <dl> <dt>echo</dt> <dd> a language construct that echoes passed parameters and does not return a value. If you want to pass more than one parameter to echo, the parameters must not be enclosed within parentheses. <div class='code-example'> <code class='code-snippet'>echo('param1 ', 'param2 ','param3')</code> → <span class='code-output'>".htmlspecialchars(sprintf('%s %s %s','param1','param2','param3'))."</span> </div> </dd> <dt>print()</dt> <dd>a language construct that outputs its parameter, always returns the value 1. <div class='code-example'> <code class='code-snippet'>print('I want ice cream.')</code> → <span class='code-output'>".htmlspecialchars(sprintf('I want ice cream.'))."</span> </div> </dd> <dt>printf()</dt> <dd>outputs a formatted string. <div class='code-example'> <code class='code-snippet'>printf('a %s with %u wings.', 'bird', 2) </code> → <span class='code-output'>".htmlspecialchars(sprintf('a %s with %u wings.', 'bird', 2))."</span> </div> </dd> </dl>" ), 5=>array( 'q'=>'How does using single versus double quotation marks differ in creating or printing strings?', 'a'=>"Strings can be interpreted or literally output. If contained within double quotes, a string will be interpreted, meaning any php variables will be converted to their values and any escaped characters will display their unescaped characters. Single quotes will result in a literal rendition of your text (except for escaped single quotes and escaped backslashes \' or \\).</p>" ), 6=>array( 'q'=>'What does it mean to escape a character in a string?', 'a'=>"To escape a character in a string you must prepend a backslash. This will override the interpreted meaning of the character and replace it with it's literal value.".' For example: in single quotations to display a single quote, you must write <b>\\\'</b>' ), 7=>array( 'q'=>'What are the three comment syntaxes in PHP? Which one can be used over multiple lines?', 'a'=>'<ol><li># comment spanning one line</li> <li>// another comment spanning one line</li> <li>/*and yet another<br/>comment spanning multiple lines*/</li> </ol>' ), 8=>array( 'q'=>'What character do all variable names begin with? What characters can come next? What other characters can be used in a variable’s name?', 'a'=>'<p>All php variables begin with the <b>$</b> followed by a letter or underscore then any combination of letters, numbers or underscores.</p> <p><span style="color:green">ALL OK</span> $_aCoolVariable, $my_name, $John4521<br/> <span class="error">NOT OK</span> $24_hours, $cost-per-unit </p>' ), 9=>array( 'q'=>'Are variable names case-sensitive or case-insensitive?', 'a'=>'<p>Variable names are <b>CASE-SENSITIVE</b>. $Error!=$error</p>' ), 10=>array( 'q'=>'What is the assignment operator?', 'a'=>'<p><b>=</b></p><p>$color<b> = </b>"blue";<br />The variable $color is assigned the value "blue"</p>' ), 11=>array( 'q'=>'How do you create a string variable?', 'a'=>'<p>A string variable is created using the assignment operator and quotations.<br /> $text = "Dog, as a devil deified, lived as a god."</p>' ), 12=>array( 'q'=>'What is the concatenation operator? What is the concatenation assignment operator?', 'a'=>'<dl><dt><b>.</b></dt> <dd>The concatenation operator acts as glue between values.<br /> $var = "make " . "peace";</dd><dt><b>.=</b></dt> <dd>The concatenation assignment operator appends the value on the right of the equal sign to the end of the left side operand.<br /> $var .= " not war;"</dd> </dl>' ), 13=>array( 'q'=>'How are constants defined and used?', 'a'=>'<p>Constants are defined using the define() function. They cannot be overwritten and are by default case sensitive. To output a constant - it must not be in quotations. They only accept null or scalar values(ie. boolean,float, int, string).<br/ > define(NAME_OF_CONSTANT, "value of constant");<br /> </p>' ) ); include('templates/review.php'); ?>