Difference between revisions of "PHP103"
m |
|||
Line 61: | Line 61: | ||
My name is "Matthew" - yes it is! | My name is "Matthew" - yes it is! | ||
</nowiki> | </nowiki> | ||
− | But what you will actually get is: | + | But what you will actually get is something like: |
+ | [[Image:escapequoteserror.png]] | ||
+ | |||
+ | To output speech marks, either single (') or double (") in echo or print statements you must ESCAPE them | ||
+ | |||
+ | == Escaping Speech Marks == | ||
+ | |||
+ | To ESCAPE speech marks, you put a '''backslash''' symbol '''only''' in front of the ones you want to print out. | ||
+ | |||
+ | So the example in the previous section becomes: | ||
+ | <nowiki> | ||
+ | <? | ||
+ | echo "My name is \"Matthew\" - oh yes it is!"; | ||
+ | ?> | ||
+ | </nowiki> | ||
+ | |||
+ | And the output you get is: | ||
+ | <nowiki> | ||
+ | My name is "Matthew" - oh yes it is! | ||
+ | </nowiki> |
Revision as of 12:54, 19 January 2007
PHP Start Symbols
<? <?php
- both of these groups of symbols indicate the start of a section of PHP code - either can be used
PHP End Symbols
?>
- these symbols indicate the end of a section of PHP code
Commenting in PHP
<? echo 'This would be printed out'; // THIS IS A SINGLE LINE COMMENT AND WON'T BE PRINTED # BELIEVE IT OR NOT, THIS IS ALSO A SINGLE LINE COMMENT /* THIS SYMBOL PAIR STARTS A MULTI-LINE COMMENT BLOCK THAT ONLY ENDS WHEN YOU GET TO THE FOLLOWING SYMBOL PAIR */ echo 'This would also be printed out'; ?>
- as shown above, there are a number of ways to include comments in PHP code
Outputing in PHP
There are essentially two ways of outputting in PHP - echo and print - there is very little difference between the two - at the high-performance end of PHP, echo is fractionally faster, however print can be used in complex expressions - for the basic level of PHP there is no difference.
<? echo 'Hello'; echo "World"; print 'Where are'; print "you?"; ?>
- all of the above are valid examples of outputting
Which symbol to use ' or "?
Again, these are essentially the same.
How do I print a ' or " in my output?
This is a very important note, that often causes problems for the novice PHP programmer.
If you try and do this:
<? echo "My name is "Matthew" - yes it is!"; ?>
You would probably expect the output to be:
My name is "Matthew" - yes it is!
But what you will actually get is something like:
To output speech marks, either single (') or double (") in echo or print statements you must ESCAPE them
Escaping Speech Marks
To ESCAPE speech marks, you put a backslash symbol only in front of the ones you want to print out.
So the example in the previous section becomes:
<? echo "My name is \"Matthew\" - oh yes it is!"; ?>
And the output you get is:
My name is "Matthew" - oh yes it is!