PHP echo Output String function detailed

Source: Internet
Author: User
echo "ASD";//String echo "ads$c";//String + variable echo ' ads$c ';//String asd$c $c is not a variable echo "SD". VS "; echo "SD", "vs"; echo $a; echo $a. $b; echo $a, $b; echo $a. $b. $c; echo $a, $b, $c; echo "kaskd{$c}asd"; echo "kakskd{$arr [' Lo ']}"; echo "kakskd{$obj->a}"; echo "KASKD". $c. " KASD "; echo "KASKD". $arr [' Lo ']. " KASD "; echo "KASKD". $obj->a. " KASD "; echo "KASKD". Func ($c). " KASD "; echo "Kaksk". ($a + 1). " DKKASD "; echo $c. " JAKSD "; Echo $c, "JAKSD"; PHP Multiline Output method echo <<<end This uses the ' Here Document ' syntax to output END; Output shorthand <?php echo $a;? > <?= $a; 
<?php echo "Hello World"; echo "This spans multiple lines. The newlines would be output as well "; echo "This spans\nmultiple lines. The newlines would be\noutput as well. "; echo "Escaping characters is do \" like This\ "."; You can use variables inside of an echo statement $foo = "Foobar"; $bar = "Barbaz"; echo "Foo is $foo"; Foo is foobar//can also use arrays $baz = Array ("value" = "foo"); echo "This is {$baz [' value ']}!"; This is Foo! Using single quotes would print the variable name, not the value of Echo ' foo is $foo '; Foo is $foo//If you are a using any of the other characters, you can just echo variables echo $foo; Foobar echo $foo, $bar; Foobarbarbaz//Some people prefer passing multiple parameters to echo over concatenation. Echo ' This ', ' string ', ' is ', ' made ', ' with multiple parameters ', Chr (10); Echo ' this '. ' String '. ' was '. ' Made '. ' with concatenation. ' "\ n"; Echo <<<end this uses the ' Here Document ' syntax to output MULTIPLE lines with $variable interpolation. Note that the here document Terminator must appear to a line with just a semicolon. No extra whitespace! END; Because Echo does not behave as a function, the following code is invalid. ($some _var)? Echo ' true ': echo ' false '; However, the following examples would work: ($some _var)? print ' true ': print ' false '; Print is also a construct, but//the IT behaves like a function, so//it could be used in the this context. Echo $some _var? ' True ': ' false '; Changing the statement around?>

The following is an official manual description:
Definition and Usage
definition and usage
the echo () function outputs one or more strings. The function of the
Echo () function is to output one or more strings. The
Syntax
Syntax
Echo (strings)
Parameter parameter description describes
Strings Required. One or more strings to is sent to the output
necessary parameters. Specifies one or more strings that need to be sent to the result
tips and notes
Prompt and attention point
note:the echo () function is not actually a function T required to use parentheses with it. However, if you want to pass more than one parameter to echo (), using parentheses would generate a parse error.
Note: the Echo () function is not a real function, so you do not have to use it necessarily. If you want to pass more than one parameter to the Echo () function, then using the parentheses "()" will produce an error.
Tip:the Echo () function is slightly faster than print ().
Hint: the Echo () function is equivalent to a simplified version of the print () function. The
tip:the Echo () function has the following shortcut syntax. See Example 5. The
Hint: the Echo () function contains the following simple notation. See details: Case 5.
Example 1
Case 1

<?php $str = "Who's Kai Jim?"; Echo $str; echo "<br/>"; echo $str. " <BR/>i don ' t know! ";? >

The output of the code above would be:
The code above will output the following result:
Who ' s Kai Jim? Who ' s Kai Jim? I don ' t know!

Example 2
Case 2

<?php echo "This Textspans multiplelines."; ?>

The output of the code above would be:
The code above will output the following result:
This text spans multiple lines.

Example 3
Case 3

<?php echo ' This ', ' string ', ' is ', ' made ', ' with multiple parameters ';?>

The output of the code above would be:
The code above will output the following result:
This string is made with multiple parameters

Example 4
Case 4
Difference of single and double quotes. Single quotes would print the variable name, not the value:
Distinguish between single quotation marks (') and double quotation marks ("). Single quotes will output the variable name, not the value of the variable:

<?php $color = "Red"; echo "Roses is $color"; echo "<br/>"; Echo ' Roses is $color ';?>

The output of the code above would be:
The code above will output the following result:
Roses is redroses is $color

Example 5
Case 5
Shortcut Syntax:
Shorthand (shortcut) syntax:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.