Php echo output string functions

Source: Internet
Author: User
Tags parse error

Copy codeThe Code is as follows:
Echo "asd"; // string
Echo "ads $ c"; // string + variable
Echo 'ads $ C'; // string asd $ c is not a variable
Echo "sd". "";
Echo "sd", "";
Echo $;
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-> }";
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;
// Abbreviated output
<? Php echo $ a;?> <? = $ A?>


Copy codeThe Code is as follows:
<? Php
Echo "Hello World ";

Echo "This spans
Multiple lines. The newlines will be
Output as well ";

Echo "This spans \ nmultiple lines. The newlines will be \ noutput as well .";

Echo "Escaping characters is done \" Like this \".";

// You can use variables inside of an echo statement
$ Foo = "foobar ";
$ Bar = "barbaz ";

Echo "foo is $ foo"; // foo is foobar

// You can also use arrays
$ Baz = array ("value" => "foo ");

Echo "this is {$ baz ['value']}! "; // This is foo!

// Using single quotes will print the variable name, not the value
Echo 'foo is $ foo'; // foo is $ foo

// If you are not using any 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 'it', 'string', 'was', '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 on
Line with just a semicolon. no extra whitespace!
END;

// Because echo does not behave like a function, the following code is invalid.
($ Some_var )? Echo 'true': echo 'false ';

// However, the following examples will work:
($ Some_var )? Print 'true': print 'false'; // print is also a construct,
// It behaves like a function, so
// It may be used in 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 echo () function outputs one or more strings.
Syntax
Syntax
Echo (strings)
Parameter Description
Strings Required. One or more strings to be sent to the output
Required parameter. Specify one or more strings to be sent to the result.
Tips and Notes
Tips and notes
Note: The echo () function is not actually a function, so you are not required to use parentheses with it. however, if you want to pass more than one parameter to echo (), using parentheses will generate a parse error.
Note: The echo () function is not a real function, so you do not need to use it. If you want to pass more than one parameter to the echo () function, using parentheses () will produce an error.
Tip: The echo () function is slightly faster than print ().
Tip: The echo () function is equivalent to the simplified version of the print () function.
Tip: The echo () function has the following cut syntax. See example 5.
Tip: The echo () function contains the following simple Syntax. For details, see Case 5.
Example 1
Case 1
Copy codeThe Code is as follows:
<? Php
$ Str = "Who's Kai Jim? ";
Echo $ str;
Echo "<br/> ";
Echo $ str. "<br/> I don't know! ";
?>

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

Example 2
Case 2
Copy codeThe Code is as follows:
<? Php
Echo "This textspans multiplelines .";
?>

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

Example 3
Case 3
Copy codeThe Code is as follows:
<? Php
Echo 'this', 'string', 'was', 'Made ', 'with multiple parameters ';
?>

The output of the code above will be:
The above code will output the following results:
This string was made with multiple parameters

Example 4
Case 4
Difference of single and double quotes. Single quotes will print the variable name, not the value:
Difference between single quotes (') and double quotes. The variable name is output in single quotes instead of the variable value:
Copy codeThe Code is as follows:
<? Php
$ Color = "red ";
Echo "Roses are $ color ";
Echo "<br/> ";
Echo 'Roses are $ color ';
?>

The output of the code above will be:
The above code will output the following results:
Roses are redRoses are $ color

Example 5
Case 5
Export cut syntax:
Short Syntax:
Copy codeThe Code is as follows:
<Html> <body>
<? Php
$ Color = "red ";
?> <P> Roses are <? = $ Color?> </P> </body>

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.