![]() |
PHP |
Home
Computers & Internet
Web Programming
PHP |
| CHARACTER STRINGS IN PHPCharacter strings are a series of character sequences, can be combinations of numbers, punctuation characters and letters, words or sentences. The following are some examples of character strings: $string3="My name iS John Smith"; $string4='john@smith.com'; When only numbers are stored in variables, no single or double quotes are used so that these variables can be used in mathematical calculations as in the following example: $firstNumber=156; // number $secondNumber=44; // number $totNumber= $firstNumber + $secondNumber; // number When only numbers are enclosed in single or double quotes, they become character strings and cannot be used in mathematical calculations as in the following example: $firstNumber="156"; // character string $secondNumber='44'; // character string You can use either single or double quotes to store Character strings in a variable but there are differences in the way PHP treats them. Single-quoted string values are stored literally ie. as is. Example: $name="John"; $string='My name is $name'; // stored as: My name is $name A \ (back slash) is used to escape an apostrophe (') in single quoted strings as the example below: $string='My mother\'s name is $name'; // stored as: My mother's name is $name Double-quoted string values are processed before the string is stored. Example: $name="John"; $string='My name is $name'; // stored as: My name is John // ie. the $name variable is evaluated to John and then stored as: My name is John Using Secial Characters In Double Quoted Strings Newline \n: Characters proceeding \n start on a new line. Example: $string="John \nSmith"; echo $string; The above outputs: John Smith Other special characters: Carriage-return character: \r Tab character: \t |
|
| Home | Privacy Policy | Terms Of Use | Contact Us |
| © 2008 - www.ToKnowMore.net |