Web Technology 2: Module 3


Due next week: compare and contrast 2 applications (one being a desktop application, and the other being a web application), Today’s class is a PHP Introduction. PHP is a server-side scripting language for creating dynamic and interactive websites. Open source, free alternative to competitors like Microsoft’s ASP. Often used together with Apache web server (but is not limited to) on various operating systems. PHP Hypertext Preprocessor, original name was personal home page? Web server interprets PHP code, not visible on the client side. Supports database (like MySQL) and may contain text, html tags, and scripts. Can run on different platforms.

<?php is the opening tag and ends with ?>. Can be placed anywhere in the document. Must end with a semi-colon. Two basic statements to output text: echo (more common) and print. Comments: // (single line), and /* … */ (multi-line). In class exercise… (opening Dreamweaver).

Like JavaScript, PHP has variables for storing values, strings, arrays, numbers, function results… Unlike JavaScript, all variables start with a ($) dollar sign. Like JS, variables are alpha-numeric — it can start with a letter or underscore (but not a number). You can have mathematical or logical operators. Case-sensitive. Can use keywords (like return or var) but it’s recommended not to. Single or double quotes are okay, just be consistent. Strings (like in JS). The concatenation operator ( + ) in JS is different in PHP… In PHP it is ( . ) (So “Hello” . “World” instead of “Hello” + “World”). PHP also ignores white space. The strlen() function is used to find a length of a string (counts the number of characters) and can also be used in JS. Example: <?php echo strlen(“Hello world!”); ?> would output 12. Both PHP and JS start counting at 0. Getting string lenghts is often used in functions (for example: counting characters in a URL). The strpos() is used to find the position for a string or character within a string. If match is found, it will return the position of the first match. If it is not found, it will return FALSE. Operators are similar to JS, but not all. There is no ===. Just the two (because it doesn’t need to find the variable type). There is && which means and. || means or. ! means not. += (x+=y) Example: x=x+y.

<?php $myname = “Jina”; echo $myname; ?> will simply output “Jina”.

If else statements are same concept as in JS, but it uses elseif instead of else if. Switch statements concept is also the same, and is a quick way of doing the if else if statements. Break basically says “if this is true, don’t worry about the rest of this function”. While and for loops are similar as well.

Going over different statements (for, while, foreach, etc.). Will go over these in more detail next week. More than 700 built-in functions available. All start with the word “function()”. Name the function so it’s easier to understand what it does. Use curly braces like in JS. You can add parameter in between the parenthesis which is like a holder (like variables). Functions can be also used to return values. arrays can store one or more values in a single variable name. Each element in the array has it’s own ID so it can be easily accessed. Three types: numeric (automatically assign an ID or manually assign an ID), associative (ID key is associated with a value), multidimensional (each element in a multidimensional array can also be an array).

PHP forms use $_GET and $_POST. They can retrieve information very quickly. It’s good to do validation on both the client side and the server side. A database needs the server side to talk to the browser. Without it, it can’t. action=”index.php” means it’s running the code within that file (index.php). Null means there’s nothing there.

Also as homework, create a sticky form (which we just created). Make a list of all the pages that were in the Sitemap (done last week) in HTML. Instructor’s notes will be uploaded by tomorrow night in the directory.

Unrelated Note:
If you haven’t already, please change your RSS subscriptions to my new feed URL: http://feeds.feedburner.com/SushiRobots. Thanks!

1 Comment Add your comment

  1. Dan

    September 19th, 2008

    It’s interesting to see how other places teach php, at my university they start you off really slow, then after a few weeks, they dump all the MySQL on you and expect you to teach yourself SQL and all the php that goes with it, hope they ease you in more gently.

Leave a comment

Next entry: Make it Modular

Previous entry: Principles of Usability: Module 2


Subscribe & Share

  • Syndication

Archive

Categories

Zalitron loves you

I WANT ROBOTS!