logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Creativity
Family Travel
Southwest USA
Irish Culture
Home Finance
Comedy Movies
Romance Novels


dailyclick
All times in EST

Full Schedule
g
g PHP Site

BellaOnline's PHP Editor

g

Introduction To Character Strings

Guest Author - Diane Cipollo

Before we start manipulating character strings with PHP, we should discuss what a character string is. A character string is a series of characters and these characters can be letters, numbers and punctuation. That's easy enough, but there are a few things to keep in mind when working with character strings and PHP.

When you store a character string in a variable, you will enclose the character string within double or single quotation marks. When you place a character string between quotation marks, you are telling the program where the character string begins and ends. The first quotation mark begins the character string and when the program encounters a second quotation mark, it knows to end the string. For example, these two lines of code are basically the same.

$string = "Gone With The Wind";

$string = 'Gone With The Wind';

Because the program ends a character string when it encounters the second quotation mark, it's a bit tricky to use quotation marks as part of the character string. If you need to use double quotation marks as part of the character string itself, you will use single quotation marks to enclose the complete string. In the example below, the double quotation marks are placed around the word old and the single quotation marks enclose the entire string. The reverse is also possible.

$string = 'Gone With The Wind is an "old" book';

You have a second option for using quotation marks within a character string. If you must use double quotation marks both to enclose the character string and within the string, you must escape the second (inside) quotation marks with a backslash \. This backslash tells the program to ignore the escaped quotation marks. The reverse is also possible.

$string = "Gond With The Wind is an \"old\" book";

Numbers are treated in a special way in most programming languages including PHP. When you work with numbers, you initially think of mathematics and you can perform many types of calculations on numbers using PHP. But when you use a number as part of a character string, you must think of that number as not a number. When numbers are part of a character string or used as a character in any way, the number is considered to be a character just like a letter. Just as you cannot add oranges and apples together, you cannot add two characters together. Just remember that you cannot perform calculations on characters even if they "look like" numbers.




This site needs an editor - click to learn more!

Add Introduction+To+Character+Strings to Twitter Add Introduction+To+Character+Strings to Facebook Add Introduction+To+Character+Strings to MySpace Add Introduction+To+Character+Strings to Del.icio.us Digg Introduction+To+Character+Strings Add Introduction+To+Character+Strings to Yahoo My Web Add Introduction+To+Character+Strings to Google Bookmarks Add Introduction+To+Character+Strings to Stumbleupon Add Introduction+To+Character+Strings to Reddit




RSS | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


For FREE email updates, subscribe to the PHP Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

g


g features
Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor