Changes

Jump to: navigation, search

PHP Operators

38 bytes added, 14:34, 13 May 2009
no edit summary
Operators in PHP, and any other prgramming programming language for that matter, enable us to perfrom perform tasks on variables and values such as assign, multiply, add, subtract and concatenate them. Operators take the form of symbols (such as + and -) and combinations of symbols (such as ++ and +=).
Operators in PHP work with ''operands'' which specify the variables and values that are to be used in the particuilar particular operation. The number and location of these operands in relation to the operators (i.e. before and/or after the operator) depends on the type of operator in question. Let's take, for example, the following simple expression:
<pre>
== PHP Assignment Operators ==
We breifly briefly covered the basic PHP assignment operator in the [[An Introduction to PHP Variables]] chapter. We will now look at this and other assignment operators in more detail.
The ''assignment operator'' is used to assign a value to a variable and is represented by the equals (=) sign. The assignment operator can also be combined with arithmetic operators to combine an assignment with a mathemtatical mathematical operation (for example to multiple multiply one value by another and assigning the result to the variable) and also to perform string concatenations.
The following table lists the seven assignment operators available in PHP, together with descriptions and examples of their use:
The PHP String concatenation operator is used to combine values to create a string. The concatenation operator is represented by a period/full stop (.) and can be used to build a string from other strings, variables containing non-strings (such as numbers) and even constants:
We will start with the operater operator in its simplest form concatenating two strings:
<pre>
== Concatenation of Numbers and Strings in PHP ==
We mentioned at the begining beginning of this section that it is also possible to mix numbers and strings in a concatenation operation to create strings. For example we can include the number 6 in our string as follows:
<pre>
<tt>11 is my lucky number</tt>
It is important to note an issue when dealing with strings and numbers. While the above works fine because we began the expression with the addition, something very different happens when we have the addition afer after the string:
<pre>
</pre>
This will now produce the desired output:
<tt>My Lucky number is 11</tt>
You can do anything in an execution operator that you could do as if you were sitting at a terminal window on the computer (within the confines of the user account under which PHP is running). Given this fact, it should not escape your attention that there are potential security risks to this, so this PHP feature should be used with care.
The excecution execution operator consists of enclosing the command to be executed in back quotes (`). The following example runs the UNIX/Linux ''uname'' and ''id'' commands to display information about the operating system and user account on which the web server and PHP module are running (note that these command will not work if you are running a Windows based server):
<pre>
?>
</pre>
 
<google>BUY_PHP_BOTTOM</google>

Navigation menu