Now we're going to talk about some advanced output options in PHP and a little more
about strings. Let's open up a brand new PHP document. I'm going to create the
string with a variable color and assign it to the string green. Normally we've
been using double quotes to encapsulate our strings. If we use double quotes, we
can't use double quotes inside because it'll break the string. Inside your
double-quoted string, you'd have to escape double quotes for them to be used. I
could place any amount of single quotes inside however. I could optionally
encapsulate my string with single quotes. The advantage to this is that if I
have a lot of double quotes, I don't have to worry about escaping them because
PHP knows that my string is delimited by single quotes. If I wanted to use
single quotes inside, I would have to escape them so that my string doesn't break.
There's one difference between using single and double quotes and that is that I
can use variable substitution inside of double quotes. For instance, I have the
variable color, which is equal to green. If I wanted to use that in a
concatenation, instead of concatenating it, I could just use double quotes and
put the variable right inside my string. If I echo out the new variable place we
can see that PHP has substituted the variable color with its value. Variable
substitution can save a lot of time and so it's handy to use double-quoted strings.
There are many times when you'll have a large amount of text that could contain any
number amount of single or double quotes, especially when you're grabbing a lot
of data from your FileMaker database or if you have a large form where people
can enter in a lot of text. In these instances, using the herdoc syntax is
really powerful. Herdoc, which is spelled h-e-r-d-o-c, allows you to delimit
when your strings begin and when they end. You can choose your own delimiter and
it'll allow any amount of single or double-quote characters to be used in between.
In the herdoc syntax, PHP will also allow variable substitution. Here's how a
herdoc works. I create my string variable and I say it's equal to, and instead
of using a single or double quote, I use three less than signs. This tells PHP
we're going to be using the herdoc syntax. Now I can choose my delimiter. Pick
any name you want. I'm going to use the word flag. Now PHP knows that the string
is going to be encapsulated between two delimiters, a flag at the beginning and
a flag at the end. I can put any amount of text in between. When I'm done with
my text, it's very important that I put in my delimiter again to tell PHP my
string has ended. It's also very important to know that this delimiter must be
on a new line and cannot be surrounded by any white space. When you're done with
your second delimiter, terminate it with a semicolon. Now our string's ready for
use. I'll output the variable string to the browser. As you can see, PHP
outputted the whole string together and didn't worry about any single or double
quotes that existed in the string. Here's a single quote right here after books.
And just like double-quoted strings, I can use variable substitution. The herdoc
syntax will substitute my variables with their values.
FileMaker 9 and PHP
Lance Hallberg
US$ 99.95
8 hours - 107 Movies
Win Vista XP 2000,ME. Mac OS X
Ground / 2 day / Next Day
33786
258 In Stock
Apex Web Media ( Hyperteach ) P.O Box 398 Bolton BL7 9YS, United Kingdom. Tel: +44 (0) 1204 592071 Fax: +44 (0) 1204 592092 Email:
Apex Web Media ( Hyperteach ) 600 17th Street, Suite 2800, Denver CO 80202 Tel: Toll free 1866 402 1903 (USA) / 434 878 4158 Fax: 1 207 433 4356 Email: