The remaining sequences $ ” & ‘ are all to
allow those characters to be printed in your string. This is
important, because as we have seen already if we use those
characters they have special meaning. Also please note that
a ‘ can be used in a string if the string is enclosed
by “ and vice versa.
allow those characters to be printed in your string. This is
important, because as we have seen already if we use those
characters they have special meaning. Also please note that
a ‘ can be used in a string if the string is enclosed
by “ and vice versa.
This can be very important especially when you are
outputting HTML to a web page, as web page tags need
enclosing parentheses around any attributes specified in the
tags, EG:
outputting HTML to a web page, as web page tags need
enclosing parentheses around any attributes specified in the
tags, EG:
<?php Print "<img src='mypic.jpg' alt='My Picture'/>"; ?>
To output an image tag. You can also do this the other way:
<?php Print '<img src="mypic.jpg" alt="My Picture"/>'; ?>
The first way seems to be the most used, I’m guessing because of the variable substitution ability, EG:
<?php $mypic = 'images/mypic.jpg'; Print "<img src='$mypic' alt='My Picture'/>"; ?>
Don’t be fooled by the $mypic being surrounded by ”, if you look at the whole line it’s the “” that matter, the inner ” will be ignored.
What next?
Well now you understand what strings are and how you can use
them, it’s time to start reading the PHP manual page on
string functions, this can be found at https://phpbuilder.com/manual/language
.types.string.php.
them, it’s time to start reading the PHP manual page on
string functions, this can be found at https://phpbuilder.com/manual/language
.types.string.php.
PHP has a huge amount of functions built into it for
handling strings, unfortunately I don’t have the space here
to go over them all. The PHP manual link above has excellent
descriptions of what each of the functions do, as always I
encourage you to explore them and see what they do.
handling strings, unfortunately I don’t have the space here
to go over them all. The PHP manual link above has excellent
descriptions of what each of the functions do, as always I
encourage you to explore them and see what they do.
Don’t worry if you use a function and it doesn’t work as
expected, play with the code until it does. It’s all about
playing with the code and understanding what does what.
expected, play with the code until it does. It’s all about
playing with the code and understanding what does what.
Until next time
Don’t tangle your strings. Check back next week when we’ll
cover numbers & maths.
cover numbers & maths.
Shawty