String Type in PHP

Filed in php-lesson1(variables) 0 comments

String Type
a string is simply a sequence of characters treated as a contiguous group.Such groups are
typically delimited by single or double quotes,
String Examples:

$str_sq = 'single quat string';
$str_dq = "double quat string";
$str_zc = "";//string with zero characters;

as I mentioned a string can be enclosed both in single and double quotation marks,that each will behave diffrently.singly quoted strings are treated literally meaning that if there were any variables inside it ,the name of the variable will be printed instead of the value of it, but double quoted strings will reaturn the value of the variable with printing of sequence of characters near it.

single quoted Strings
Escept some characters, singly quoted strings will read and stroe their characters literary, meaning that if there is a varaible inside the string value, it will print the variable name with dollar sign itself rather than returning its value.
Example

$Literally = 'This $variable wont have its value returned';
print($Literally);

Outputs:

This $variable wont have its value returned

nesting quotations in string
There are Times where you want to have one wod to be emphasized or to isolate a word from the body of your written sentens that will be accomplsihed so by using quotes by as the quotes are in the PHP language structure, How to nest it?
if you want to do so first you must see if you wat the string to be read litterally
and if you want a word inside your sentence to be quoted, the quotation must be vary from the quotation used for the uper leve
forexamlpe if you are using the signle quotation then you should use the double inside for litteral strings
if you are tring to use double qoutation for isolate or emphasise a word then you must use the single quotaton on the uper level
Example:

$single_quote = 'This contains "double-quotes" in this string but single qoute for the variable';
$double_quote = "This contains 'single-quotes' in this string but double qoutes for the variable";

there is also another way to have both quotes for the variable string and inside of the variabel that could be accomplishde by using the \’ and if you are trying to use double quotes you should use \” inside the string
Example:

$single_quote = 'This contains \'single-quotes\' both for variable and insdoe of the string';
$double_quote = "This contains \"double-quotes\" both for variable and insdoe of the string";

Provides:

This contains 'single-quotes' both for variable and insdoe of the string
This contains "double-quotes" both for variable and insdoe of the string

Related posts:

  1. Assigning Variables in PHP
  2. Double Type in PHP
  3. Declaring variables in ActionScript 3
  4. NULL Type in PHP
  5. Integer Type in PHP
  6. Variables default values in PHP
  7. Variable Scope In PHP
Posted by voshka   @   12 March 2010 0 comments

Share This Post

RSS Digg Twitter StumbleUpon Delicious Technorati

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

Previous Post
«
Next Post
»
CrossBlock designed by DeltaManual.Com  |  In conjunction with Web Hosting   |   Web Hosting   |   Reverse phone