Friday, April 5, 2013

PHP Strings and Patterns - Quoting

String is series of character where character is as byte. PHP support 256 characters.

There is four type of strings

  • Single quote
    Single quote string is fast render string, as it never parse a variables exist within it.
    Single quote string start  and end with single qoute(')

    Following are the example of Single quote

    $certificaton='Zend PHP5.3';
    echo '200-530 cerrfication \n ';
    echo 'I am doing preparation for $certificaton ' 
    
    
    
    
  • Double quoted
    Double quoted string parse the variables inside in it.
    It start and end with double qoute(")

    Following are the example of Double Quote
    $certificaton='Zend PHP5.3';
    echo "200-530 cerrfication \n ";
    echo "I am doing preparation for $certificaton "; 
  • Heredoc syntax
    A third way to delimit strings is the heredoc. After this operator(<<<), an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation. The closing identifier must begin in the first column of the line. the identifier must follow the same naming rules as any other label. it must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore. It also parse the variable exist within in it.

    Following are the example of Heredoc Syntax.
    $certificaton='Zend PHP5.3';
    $string = <<<LABEL
    Do study to get $certificaton
    LABEL;
    echo $string;
    






  • Nowdoc syntaxA Fourth way to delimit strings is the nowdoc(>=PHP5.3). After this operator(<<<), an identifier is provided with enclosed in single quote, then a newline. The string itself follows, and then the same identifier again to close the quotation. The closing identifier must begin in the first column of the line. the identifier must follow the same naming rules as any other label. it must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore. It never parse the variable exist within in it.

    Following are the example of NowDoc Syntax

  • $certificaton='Zend PHP5.3';
    $string = <<<'LABEL'
    Do study to get $certificaton
    LABEL;
    echo $string;
    

No comments:

Post a Comment