PHP/Basic Code
From r00tedvw.com wiki
(Difference between revisions)
(→Basics) |
|||
Line 34: | Line 34: | ||
Outputs: Hello, world!</nowiki> | Outputs: Hello, world!</nowiki> | ||
Each string above is defined between double quotes. The "dots" are between them and combine them together to form 1 long string. | Each string above is defined between double quotes. The "dots" are between them and combine them together to form 1 long string. | ||
+ | |||
+ | ==Variables== | ||
+ | Variables in php are stored the same way as bash scripting, the variable name being defined by starting with a "$" | ||
+ | <nowiki>ie. | ||
+ | <?php | ||
+ | $myName = "r00tedvw"; | ||
+ | echo $myName; | ||
+ | ?></nowiki> |
Revision as of 01:37, 26 December 2015
Contents |
Basics
- .php
- all PHP pages end with the .php extension, this tells the browser there is php code in the file.
delimiters - start & stop
- <?php
- all php code begins with this.
- ?>
- all php code ends with this
output text
- echo
- just like with scripting, echo can be used to output text
ie. <p> <?php echo "My first line of PHP!"; ?> </p>
Arithmetic
php is capable of doing basic arithmetic, take the following for example using "echo"
<?php echo 17 * 123; ?> Outputs: 2091
Operators
concatenation
- joins strings together
<?php echo "Hello," . " " . "world" . "!"; ?> ---- Outputs: Hello, world!
Each string above is defined between double quotes. The "dots" are between them and combine them together to form 1 long string.
Variables
Variables in php are stored the same way as bash scripting, the variable name being defined by starting with a "$"
ie. <?php $myName = "r00tedvw"; echo $myName; ?>