As any other programming language, php has operators.
They are:
- Arithmetic
- Assignment
- Comparison
- Boolean Logic
The operators are symbols used within an expression to specify the manipulations to be performed while evaluating that expression.
They are similar with the ones used in other languages (C, C++…) so if you mastermind their logic, you make a huge step forward in your programming skills in general.
Arithmetic operators:
| Operator | Example | Description |
| + | a=11
a+4 is 15 | Add |
| - | b=7
10-b is 3 | Subtract |
| * | c=5
c*3 is 15 | Multiply |
| / | d=9
d/3 is 3 | Divide |
| % | 15%2 is 1
15%4 is 3 | Division remainder also called "Modulus" |
| ++ | e=6
e++ is 7 | Increment |
| -- | f=6
f-- is 5 | Decrement |
Assignment operators:
| Operator | Example | Description |
| = | a=b | a equal b |
| += | a+=b is a=a+b | add b to a |
| -= | c-=d is c=c-b | subtract c from d |
| *= | a*=b is a=a*b | a multiply by b |
| /= | a/=b is a= a/b | a divide by b |
| .= | a.=b is a=a.b | |
| %= | a%=b is a=a%b | |
Comparison operators:
| Operator | Example | Description |
| == | 7==9 is false | Is equal to |
| != | 7!=9 is true | Isn't equal to |
| < > | 77< > 87 is true | Is not equal |
| < | 3<33 is true | Is less then |
| <= | 3<=33 is true | Is less then or equal |
| > | 5>55 is false | Is greater then |
| >= | 5>=55 is false | Is greater then or equal |
Boolean Logic operators:
| Operator | Example | Description |
| && | a=10 and b=5 the parenthesis
(a<20 && b>2) is true | and |
| || | a=10 and b=5 the parenthesis
(a==5 || b==3) is false | or |
| ! | a=10 and b=5 the parenthesis
!(a==b) is true | not |
Note: Notice that in last 2 tables the return is a Boolean value of true or false not a number
Now we have all operators, we take a sort break and continue with Statements:
Until next time be well.
Michey
Related posts:
To work with PHP, your server must support PHP files.
For most servers “.php” is a default extension for PHP files, but you have to ask and be sure that this is the case.
If the answer is NO, you have two choices:
- Do yourself a favor and choose a server which has what you need (Apache, PHP, MySQL), a great example is Hostgator, this is the one I am using and recommend, but you have more then one choice
- If you are a geek, and you want to save bandwidth and develop locally on your own Server, you need to install:
From this point, I presume that your Server has activated support for PHP and all files name.php are handle by PHP.
What is a “name.php” file?
It is an HTML file enhanced with a new family of tags. We will discus all of them in future posts .
Theoretically as PHP files are just plain text files you can use any editor to create and edit them.
But even though you can use simple text editor like Notepad, I highly recommend to use an editor capable of syntax highlighting and advance text manipulation.
Examples of editors you can use are :
- Eclipse (with PHP plugin ) , choose “Eclipse for PHP Developers “, it is Free
- Editplus, one month trial, and $35/month after
- Dreamweaver
- Frontpage
Now that we know what we need, I’ll give you the simplest .php file, it is called HelloDevelopers.php:

What we see:
- It is an HTML file which starts and ends with html and /html, we have a head and a body as a typical HTML file
- Within the body we have a php line which start with question mark php and end with question mark
The example is the simplest possible but you and I are in this moment php programmers. Don’t we?
I’ll take a break now and let you create your own PHP environment, as I want you to be able to follow me as we progress.
Until next time be well
Related posts:
Posted in PHP Tutorial
|
Tagged Apache, Dreamweaver, Eclipse, Editplus, Frontpage, MySQL, php, php developers, php environment, php file, php requirements, php tags, servers
|
From the beginning “.php”, the Hypertext Processor, was confusing for me, so now from the start I want to clarify the legitimate questions a beginner may have:
- What is “php”?
- Why we need to learn php?
- What php can do for us?
- What do we need?
PHP is a free general purpose scripting language that was design for Web developers to help producing dynamic Web pages.
It was created by Danish/Greenlandic Rasmus Lerdorf in 1995 and has been in continuous development ever since.
The language itself is easy to learn but you need to use PHP in conjunction with MySQL, and JavaScript. This is how you create responsive, data-driven websites. Sometime you will use PHP in combination with HTML but this is not enough to produce modern websites with dynamic data and user interaction.
Learning PHP, MySQL, and JavaScript, and how they work together, will help you:
- Understand the essentials of PHP and the basics of object-oriented programming
- Master MySQL, and use properly database structure
- Create interactive web pages with PHP and MySQL by integrating forms and other HTML features
- Use JavaScript, for functions and event handling
- Use libraries and packages such as:
- The Smarty web template system,
- The Yahoo! User Interface Library (YUI)
- Learn how to make Ajax calls and turn your website into a highly dynamic environment
- Upload and manage files and images
- Validate user input and secure your applications against being hacked
- Learn to use the best practices for error handling
Did I say the sky is the limit? I think I already did!
I hear you, we are just bloggers, why we need all of this huge amount of knowledge to write some post? The devil is in details. It is true that WordPress platform gives us an enormous amount of functionality with thousands of plug-ins which in general are very easy to use. But it is an open source platform, so there are some pitfalls as well.
From time to time:
- Just to use properly some plug-ins, we need to enter in a .php file and add/change/delete something
- Some themes don’t work with some plug-ins and again we need to modify .php files
- Some widgets don’t work with some themes, so again we have to mess with .php files
- If an artist is hiding in your sole, you want to modify your blog to look or perform in a different way, so you have to implement changes in your Blog’s .php files
- Maybe some day you want to create your own theme
- If you want to sell something, the easy way is to use the $7 Script. To install and enhance the script with what you need you basically modify a bunch of .php files
I can continue… but I think you have an idea that some knowledge of .php will bring your blogging experience to a different level.
Until next time be well Michey
Related posts:
Php Syntax Part 1
Prerequisite are: Basic HTML, javascript and in case in which you want to design Php applications from scratch, some Object Oriented Design is very useful.
At this point we already know that PHP stands for Hypertext Preprocessor, it is a server-side scriptic language which are executed on the server, it is free to download, it is open-source, it support many Databases but we work with MySQL, can be used cross-platforms: Windows, Unix, Linux.
Notes:
*) For clarity of long programs, I suggest the end of a php scriptic block (?>) to be on a separate line, and when you have many code lines, each code line must end with a semicolon separator.
**) When you save the file must have a “.php” extension, not “.html”. In addition to “.php” you can use “.php3” or “.phtml“, but I suggest to stay only with “.php”.
Php Scripting Block, Comments, Variable, Strings.
We already know how a php scriptic block looks like.
And we will start with comments which can be a single line comment or block of multi lines comment which must have an end (*/) as you can see in the next picture:
We use variables to store values which can be: numbers, text-string, arrays. We declare a variable just once in the program and use it as many time as we need.
Note: A variable doesn’t need to be declared before adding a value to it, and we don’t need to tell php which type the variable is because, based in value the php will determine the correct value. Giving names with significance is for programmers not for php.
Variables must be named starting with a letter or undescore, it contains only alpha-numeric characters and underscore (A-Z, 0-9, _). We must use just one word for naming, so if you need 2 words you must use “_” or capitalize the second word. If you look at above example, I use on purpose: test_str and myText.
In the next post we will continue with more php systax.
Until next time be well. Michey
Related posts: