Welcome to PHPMule.com
A blog site which I am posting to during my learning of the popular programming language PHP. Feel free to leave comments!
-
PHP - Single vs Double Quotation Marks
In PHP you can use either single quotation marks or double quotation marks. Anything contained between single quotation marks will be treated literally and anything between double quotation marks will be interpreted. For example:
echo ‘Here is a variable and the variable is $var’;
would literally output: Here is a variable and the variable is $var
If you put this line between double quotation marks it would output the following:
Here is a variable and the variable is 15.
There is one case where you may need to alternate the use the single and double quotes. Look at the following example:
echo ‘I will be going on holiday shortly and I’m taking my laptop with me’;
You will notice that you have used the ‘ symbol three times so therefore it will give a parse error. In this case you will have to use the double quotes. By the way this can happen vice versa as well so be careful when using single and double quotes in sentences.
(Post created on Friday, May 1st 09 at 23:35)
-
PHP - Trimming Strings
The trimming string functions:
In a string you can have excess whitespace you don’t need but is very useful if you want to store this string in a file or database.
The trim() function will remove any whitespace from the beginning or end of string for example if you had the string “ celebrity ” the resulting string will be “celebrity” as all the whitespace is removed from the start and end.
There are two other trimming functions and these are:
ltrim() and rtrim()
These functions do the same thing as the ‘trim()’ function but instead the first one removes whitespace from the left hand side and the other one removes whitespace from the right hand side.
The main purpose of trimming is to have cleaner input from your visitors, for example if they were to accidently include a space before they input their name on a form.
(Post created on Monday, April 13th 09 at 16:30)
-
PHP - Variable Types
In PHP, there are 6 data types:
Some of them everybody may know of already:
String - This data type has quite simply a string of data such as flower231tulip
Integer - This data type holds numbers such as 834
Float - This data type is used for real numbers such as 12.45
Boolean - This data type is used for true or false values
Array - Stores multiple data items
and the Object data type.
If a variable hasn’t got a value the data type is known as ‘NULL‘ to indicate nothing basically!
(Post created on Monday, April 6th 09 at 13:25)
-
PHP Variables
In PHP, variables are used for storing a value, whether it’s a text string or numbers.
A variable in PHP has to start with the ‘$’ sign followed by whatever you want to call the variable and then the variables value which would look something like this:
$dvd = “Casino Royale”
a number can also be stored in a variable:
$ageoffilm = 3
So what would happen if we made a PHP script using these variables?
<?php
$dvd = “Casino Royale”;
$ageoffilm = 3;
?>
<html>
<head><title>Movies</title></head>
<body>
<?php
echo “Best bond film: ” . $dvd . “<br />”;
echo “How old is the film: ” . $ageoffilm . “<br />”;
?>
</body>
</html>
This would output:
Best bond film: Casino Royale
How old is the film: 3By the way you may notice the cotcatination operator which is basically just a period “.”
You can use this operator to add strings together as shown in the example above.
(Post created on Sunday, April 5th 09 at 23:45)
-
Calendar
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Jun | ||||||
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | ||||
Archives
Recent Articles
- PHP - Rounding Off Numbers
- PHP - Single vs Double Quotation Marks
- PHP - Loading Files Into Your PHP Script By Using require() and include()
- PHP - Replacing Strings With Other Strings
- PHP - Finding Strings Within Strings
- PHP - Using strlen() To Test String Length
- PHP - Using The explode() Function
- PHP - Changing The String Case
- PHP - The nl2br() Function
- PHP - Trimming Strings
Links
Categories
- PHP (22)
- Uncategorized (1)


