O'Reilly logo

PHP and MySQL for Dynamic Web Sites: Visual Quickpro Guide, Second Edition by Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

About Strings

The first—arguably most important—variable type I’ll go into is strings. A string is merely a quoted chunk of letters, numbers, spaces, punctuation, and so forth. These are all strings:

  • 'Tobias'

  • "In watermelon sugar"

  • '1,000'

  • 'February 3, 2005'

To make a string variable, assign a string value to a valid variable name:

$first_name = 'Tobias';

$today = 'February 3, 2005';

To print out the value of a string, use either echo() or print():

echo $first_name;

To print the value of string within a context, use double quotation marks:

echo "Hello, $first_name";

In a way, you’ve already worked with strings once—when using the predefined variables in the preceding section.

To use strings

1.
Create a new HTML document in your text editor, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required