When they're used in computer programs, pieces of text are called strings. This is because they consist of individual characters, strung together. Strings can contain letters, numbers, punctuation, spaces, tabs, or any other characters. Some examples of strings are I would like 1 bowl of soup, and "Is it too hot?" he asked, and There's no spoon!. A string can even contain the contents of a binary file such as an image or a sound. The only limit to the length of a string in a PHP program is the amount of memory your computer has.
Defining Text StringsThere are a few ways to indicate a string in a PHP program. The simplest is to surround the string with single quotes:
print 'I would like a bowl of soup.'; print 'chicken'; print '06520'; print '"I am eating dinner," he growled.';
Since the string consists of everything inside the single quotes, that's what is printed:
I would like a bowl of soup.chicken06520"I am eating dinner," he growled.
The output of those four print statements appears all on one line. No linebreaks are added by print.[1]
Join Free Now : PHP Tutorial
Thursday 14 May 2009
Working with Text and Numbers
PHP can work with different types of data. In this chapter, you'll learn about individual values such as numbers and single pieces of text. You'll learn how to put text and numbers in your programs, as well as some of the limitations the PHP interpreter puts on those values and some common tricks for manipulating them.
Most PHP programs spend a lot of time handling text because they spend a lot of time generating HTML and working with information in a database. HTML is just a specially formatted kind of text, and information in a database, such as a username, a product description, or an address is a piece of text, too. Slicing and dicing text easily means you can build dynamic web pages easily.
Join Free Now : PHP Tutorial
Most PHP programs spend a lot of time handling text because they spend a lot of time generating HTML and working with information in a database. HTML is just a specially formatted kind of text, and information in a database, such as a username, a product description, or an address is a piece of text, too. Slicing and dicing text easily means you can build dynamic web pages easily.
Join Free Now : PHP Tutorial
Subscribe to:
Posts (Atom)