Phpecho output string function details _ PHP Tutorial

Source: Internet
Author: User
Tags parse error
Phpecho output string function details. Copy the code as follows: echoasd; string echoads $ c; string + variable echoads $ c; string asd $ c is not the variable echosd. vs; echosd, vs; echo $. $ B; The 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 < This uses the "here document" syntax to output
END;
// Abbreviated output
  



The code is as follows:


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 < 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

The code is as follows:


$ Str = "Who's Kai Jim? ";
Echo $ str;
Echo"
";
Echo $ str ."
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

The code is as follows:


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

The code is as follows:


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:

The code is as follows:


$ Color = "red ";
Echo "Roses are $ color ";
Echo"
";
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:

The code is as follows:



$ Color = "red ";
?>

Roses are



The http://www.bkjia.com/PHPjc/321769.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/321769.htmlTechArticle code is as follows: echo "asd"; // string echo "ads $ c"; // String + variable echo 'ads $ C '; // the string asd $ c is not the variable echo "sd ". "vs"; echo "sd", "vs"; echo $. $ B ;...

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.