google ads

Tuesday, September 15, 2009

PHP Operators

Operator Description Example Result
+ Addition x=2
x+2 4
- Subtraction x=2
5-x 3
* Multiplication x=4
x*5 20
/ Division 15/5
5/2 3
2.5
% Modulus (division remainder) 5%2
10%8
10%2 1
2
0
++ Increment x=5
x++ x=6
-- Decrement x=5
x-- x=4



Assignment Operators
Operator Example Is The Same As
= x=y x=y
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
.= x.=y x=x.y
%= x%=y x=x%y
Comparison Operators
Operator Description Example
== is equal to 5==8 returns false
!= is not equal 5!=8 returns true
> is greater than 5>8 returns false
< is less than 5<8 returns true
>= is greater than or equal to 5>=8 returns false
<= is less than or equal to 5<=8 returns true
Logical Operators
Operator Description Example
&& and x=6
y=3
(x < 10 && y > 1) returns true
|| or x=6
y=3
(x==5 || y==5) returns false
! not x=6
y=3
!(x==y) returns true

Variable Naming Rules

• A variable name must start with a letter or an underscore "_"
• A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ )
• A variable name should not contain spaces. If a variable name is more than one word, it should be separated with underscore ($my_string), or with capitalization ($myString)

PHP is a Loosely Typed Language

In PHP a variable does not need to be declared before being set.
In the example above, you see that you do not have to tell PHP which data type the variable is.
PHP automatically converts the variable to the correct data type, depending on how they are set.
In a strongly typed programming language, you have to declare (define) the type and name of the variable before using it.
In PHP the variable is declared automatically when you use it.

Basic PHP Syntax

A PHP scripting block always starts with . A PHP scripting block can be placed anywhere in the document.
On servers with shorthand support enabled you can start a scripting block with .
For maximum compatibility, we recommend that you use the standard form (?>
A PHP file normally contains HTML tags, just like an HTML file, and some PHP scripting code.
Below, we have an example of a simple PHP script which sends the text "Hello World" to the browser:

Each code line in PHP must end with a semicolon. The semicolon is a separator and is used to distinguish one set of instructions from another.
There are two basic statements to output text with PHP: echo and print. In the example above we have used the echo statement to output the text "Hello World".
Note: The file must have the .php extension. If the file has a .html extension, the PHP code will not be executed.

Suggestions:

• Contact a local Non-Profit Corporation and ask them if you can volunteer to create a web site for their organization.
• Create a personal site including your resume and references, information about you (family, interests, hobbies)
• Create a site marketing a fictitious company or product.
• Create a site about your hometown or favorite place to visit, include places to stay, spots to visit, restaurants to dine at and other interesting facts.
• BE CREATIVE!!
Your pages must include the following:
• Section headers - used appropriately • Bold and italic fonts
• Centered text • Paragraphs
• An ordered, unordered, or definition list • Horizontal rules
• Graphic images - Be sure to use height/width and Alt tags on your images. (links to image sites can be found at putertutor.net) Use graphics for navigation buttons. • Links to other pages & external sites
• A table • E-mail links and Navigation bars (that allow you to navigate most/all the pages in your site) at the bottom of every page. Contact information at the bottom of every page.
• Special characters • A form (including JavaScript functions)
• Background & text color (search the web for images or click here)
• CSS - inline, embedded, or linked style sheet (optional). If you use CSS on your site, make sure that your site looks clean in Netscape 4.7. For more info on Netscape and CSS search http://www.tinkertech.net for resources.

While you have not learned about creating your own graphics, you should still take the design principles from the Web Design Workshop and the Non-Designers Workbook into consideration. The site should look professional; it will be a part of your portfolio to show to employers.

FINAL PROJECT

Sign-up for an account at brainbench.com and take the HTML 3.2 test. Submit your results to your instructor (be sure to include your name on the results page).
Using what you have learned in the HTML book, the Non-Designer's Web Book, and the Web Design Workshop create your own web site (minimum of EIGHT created pages) and upload it to an account at Tripod or on another server. Place a link from your homework page to your final project. Notify your instructor via email, rwood@cccoe.k12.ca.us, when the site is complete. The site topic might be one of following:

Tutorial 3 – Designing a Web Page

click the Foreground Color box to see an example of a color dialog box. This dialog box can be used to find out the Hex value of an RGB color and visa versa.
EyeDropper is a small software program that determines the RGB and Hex color values of a web page or any other object. Eyedropper is installed on all the systems. Start > Programs > Web Design > EyeDropper