Posts tagged Web Programming
HTML 4/XHTML 1.0 Tag List
Jun 21st
DTD referrs to the doc type and indicated which tags are allowed F = Frameset, S = Strict T = Transitional.
| Tag | Description | DTD | XHTML 1.1 |
|---|---|---|---|
| <!–…–> | Comment in HTML | FST | YES |
| <!DOCTYPE> | Sets document type | FST | YES |
| <a> | Sets an anchor | FST | YES |
| <abbr> | Sets an abbreviation | FST | YES |
| <acronym> | Sets an acronym | FST | YES |
| <addres> | Sets contact information for the author/owner of a document | FST | YES |
| <applet> | Deprecated: Sets an embedded applet | FT | NO |
| <area /> | Sets an area inside an image-map | FST | NO |
| <b> | Sets bold text | FST | YES |
| <base /> | Sets a default address or default target for all links on a page | FST | YES |
| <basefont /> | Deprecated: Sets a default font, color, or size for the text in a page | FT | NO |
| <bdo> | Sets text direction | FST | NO |
| <big> | Sets big text | FST | YES |
| <blockquote> | Sets a long quotation | FST | YES |
| <body> | Sets a document’s body | FST | YES |
| <br /> | Sets a single-line break | FST | YES |
| <button> | Sets a push button | FST | YES |
| <caption> | Sets a table caption | FST | YES |
| <center> | Deprecated: Sets center text | FT | NO |
| <cite> | Sets a citation | FST | YES |
| <code> | Sets computer code text | FST | YES |
| <col /> | Sets attribute values for one or more columns in a table | FST | NO |
| <colgroup> | Sets a group of columns in a table for formatting | FST | NO |
| <dd> | Sets a description of a term in a definition list | FST | YES |
| <del> | Sets deleted text | FST | NO |
| <dfn> | Sets a definition term | FST | YES |
| <dir> | Deprecated: Sets a directory list | FT | NO |
| <div> | Sets a block-level section of a document | FST | YES |
| <dl> | Sets a definition list | FST | YES |
| <dt> | Sets a definition term (or item) | FST | YES |
| <em> | Sets emphasized (or italic) text | FST | YES |
| <fieldset> | Sets a border around elements in a form | FST | YES |
| <font> | Deprecated: Sets font, size, and color for text | FT | NO |
| <form> | Sets a form for user input | FST | YES |
| <frame /> | Sets a window in a frameset | F | NO |
| <frameset> | Sets a set of frames | F | NO |
| <h1> to <h6> | Sets different headings | FST | YES |
| <head> | Sets the head section of an HTML document | FST | YES |
| <hr /> | Sets a horizontal line | FST | YES |
| <html> | Sets an HTML document | FST | YES |
| <i> | Sets italic (or emphasized) text | FST | YES |
| <iframe> | Sets an inline frame | FT | NO |
| <img /> | Sets an image | FST | YES |
| <input /> | Sets an input field in a form | FST | YES |
| <ins> | Sets inserted text | FST | NO |
| <isindex> | Deprecated: Sets a searchable index related to a document | FT | NO |
| <kbd> | Sets keyboard text | FST | YES |
| <label> | Sets a label for an input element | FST | YES |
| <legend> | Sets a legend for a fieldset | FST | YES |
| <li> | Sets a list item | FST | YES |
| <link /> | Sets the relationship between a document and an external resource | FST | YES |
| <map> | Sets an image-map | FST | NO |
| <menu> | Deprecated: Sets a menu list | FT | NO |
| <meta /> | Sets metadata about the document | FST | YES |
| <noframes> | Sets alternative content for users who do not support frames | FT | NO |
| <noscript> | Sets alternative content for users who do not support client-side scripts e.g. JavaScript | FST | YES |
| <object> | Sets an embedded object | FST | YES |
| <ol> | Sets an ordered list | FST | YES |
| <optgroup> | Sets a group of related options in a form select list | FST | YES |
| <option> | Sets an option in a form select list | FST | YES |
| <p> | Sets a paragraph | FST | YES |
| <param /> | Sets a parameter for an object | FST | YES |
| <pre> | Sets preformatted text | FST | YES |
| <q> | Sets a short quotation | FST | YES |
| <s> | Deprecated: Sets strikethrough text | FT | NO |
| <samp> | Sets sample computer code | FST | YES |
| <script> | Sets a script type | FST | YES |
| <select> | Sets a drop down list | FST | YES |
| <small> | Sets small text | FST | YES |
| <span> | Sets a inline-section of a document | FST | YES |
| <strike> | Deprecated: Sets strikethrough text | FT | NO |
| <strong> | Sets strong (or bold) text | FST | YES |
| <style> | Sets an internal style sheet | FST | YES |
| <sub> | Sets subscript text | FST | YES |
| <sup> | Sets superscript text | FST | YES |
| <table> | Sets a table | FST | YES |
| <tbody> | Groups a table body | FST | NO |
| <td> | Sets a table cell | FST | YES |
| <textarea> | Sets a textarea for an input field | FST | YES |
| <tfoot> | Groups a table footer area | FST | NO |
| <th> | Sets a table header cell | FST | YES |
| <thead> | Groups a table header area | FST | NO |
| <title> | Sets the title of the document | FST | YES |
| <tr> | Sets a table row | FST | YES |
| <tt> | Sets teletype text | FST | YES |
| <u> | Deprecated: Sets underlined text | FT | NO |
| <ul> | Sets an unorderd list | FST | YES |
| <var> | Sets a variable part of a text | FST | YES |
| <xmp> | Deprecated: Sets preformatted text | None | NO |
PHP #5: More Loops
Apr 19th
There are a few other types of loops in addition to while loops that we learned about in Part 4.
Do-While Loop
A do-while loop is very similar to a while loop. The only difference is that the condition is evaluated after each loop iteration, rather than before. The syntax is like this:
1 2 3 | do { // some code here } while (condition) |
Since the condition isn’t evaluated until after the loop body, the loop body is always executed at least once, whether or not the condition is true. Once it does get to the condition, if it is true, it goes back up to the top of the loop body. If it is false, the loop terminates.
1 2 3 4 5 | $i = 11; do { print "The number is $i<br />"; ++$i; } while ($i <= 10) |
The above code prints:
The number is 11<br />
even though the condition is not true. The loop body always executes once.
For Loop
The for loop is a bit more complicated. The syntax looks like this:
1 2 3 | for (initial-expression; condition; loop-end-expression) { //some code goes here } |
The initial-expression is evaluated only once, at the very beginning of the loop. The condition is then evaluated. If the condition is true, the body of the loop executes. Then the loop-end-expression is run. The process then starts over again with evaluating the condition. A for loop is generally used to do simple bounding loops, like this:
1 2 3 | for ($i = 1; $i <= 10; ++$i) { print "The number is $i<br />" } |
As you’ll notice, the same exact thing can be done with a while loop, but many prefer the for loop as it is more compact:
1 2 3 4 5 | $i = 1; while ($i <= 10) { print "The number is $i<br />"; ++$i; } |
More Looping Examples
Let’s try using a for loops to create a multiplication table.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | $start = 1; $end = 10; print '<table border="1" cellspacing="0" cellpadding="5">'; for ($y = $start - 1; $y <= $end; ++$y) { print "<tr>"; for ($x = $start - 1; $x <= $end; ++$x) { if ($y == $start - 1) { print "<td><b>$x</b></td>"; } else if ($x == $start - 1) { print "<td><b>$y</b>"; } else { print "<td>" print $x*$y; print "</td>"; } } print "</tr>"; } print "</table>"; |
Notice that there is a for loop inside of another for loop. Trace the above code carefully to see how it works. This code will produce the following table:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 2 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 |
| 3 | 3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 |
| 4 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | 32 | 36 | 40 |
| 5 | 5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 |
| 6 | 6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 | 54 | 60 |
| 7 | 7 | 14 | 21 | 28 | 35 | 42 | 49 | 56 | 63 | 70 |
| 8 | 8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | 80 |
| 9 | 9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 | 81 | 90 |
| 10 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 100 |

