Saturday, December 8, 2012

PHP Strings - PHP Lesson 2

PHP Strings
By Stephon Unomon

 

In PHP, as a general rule, a String is any line of text contained within quotation marks. You can use either double quotation marks (“) or single quotation marks also known as apostrophes (‘) in a string. Strings could be considered the building blocks of PHP, considering most all data is going to come from what’s in a string.

 

<?php

$double = "quotation marks.";

$single = 'single quotes.';

?>

When using single quotes, you need to “escape” the apostrophe with the slash (just like you would with double quotation marks) if you wish to display it in the output text...

 

<?php

echo 'Wouldn\'t you like a bagel?';

?>

Special commands within strings...

 

There are some “secret commands” you can use within strings to manipulate the output text:

\n:  makes a new line

\r:  a carriage return

\t:  a tab
 
\$:  shows a dollar sign - remember PHP will be looking for a variable if you want to display a dollar sign and don’t use a slash...and throw an ugly error!

Kool PHP Suite - PHP User Interface Tools & Components

No comments:

Post a Comment