Username:
Password:
FileMaker 9 & PHP Foundations Tutorials

PHP Basics / Advanced Output pt. 1

Subtitles of the Movie

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.

Tutorial Information

Course: FileMaker 9 & PHP Foundations
Author: Lance Hallberg
SKU: 33786
ISBN: 1-933736-99-2
Release Date: 2007-08-22
Duration: 9.5 hrs / 107 lessons
Work Files: Yes
Captions: For Online University members only
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 81,350 Video Tutorials (20,800 free)
  • Video Available as Flash or QuickTime
  • Over 782 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available