Welcome to Bucaro TecHelp!

Bucaro TecHelp
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Victims of Sandy Hook

Stop the Slaughter of Innocents. Congress is bought and paid for by gun lunatics and gun promotion groups. If you want to live in a safe America, help buy Congress back for America. Send a donation to Mayors Against Illegal Guns, 909 Third Avenue, 15th Floor New York, NY 10022

Working With Strings in PHP

Computer programs usually work with some form of data. One of the most common forms of data used in PHP is a text character or an array of text characters. An array of text characters is called a string variable, or just a string.

To define a string variable, you place the characters within quotes and use the equals sign (=) to assign the string value to a properly named variable. You can place the string characters within single quotes or double quotes, but the you must use the same type of quotation mark at the end of the string that you used at the beginning of the string.

A string character can be a letter, digit, space, or punctuation mark. Shown below are examples of properly declared string variables:

$title = "PHP and MySQL for Dynamic Web Sites";
$ISBN = '0-321-78407-3';

To display the value of a string on a webpage you can use the print function as shown below:

$author = "Larry Ullman";

print $author;

You can also use the print function to print a string directly, but this type of string would actually be a string constant because you could not change its value programmatically at run time. An example of this is shown below:

print "bucarotechelp.com";

Using Escape Characters

If you want to use quotation marks within a string, you can use the opposite type of quote than you used to define the sting. For example if you want to use double quotes within a sting you must use single quotes to define the string. An example of this is shown below:

$define = 'A "string" is an array of characters.';

If you must use the same type of quotation mark within a string that you used to define the string, then you must use the quotation mark escape character. An example of this is shown below:

$statement = "Jerry said, \"I didn't eat the last piece of pizza.\"";

Below are some other useful escape characters:

EscapeUse For
\nnew line
\$dollar sign

Concatenating Strings

To concatenate means to connect in series. When you concatenate stings you connect two or more stings together. In PHP a period (.) is the concatenation operator. An example of concatenating strings is shown below.


$first = "Jim";
$last = " Shoe";

$name = $first . $last;
print $name;


The first line of code defines the variable $first and assigns it the string "Jim". The second line defines the variable $last and assigns it the string " Shoe". The third line uses the concatenation operator to combine $first and $last and assigns the result to the variable $name. The last line uses the print function to print the value of $name, which would be "Jim Shoe".

RSS Feed RSS Feed

Follow Stephen Bucaro Follow @Stephen Bucaro

Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2017 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268