PHP echo Output String function detailed _php basics

Source: Internet
Author: User
Tags parse error
Copy Code code as follows:

echo "ASD";//String
echo "ads$c";//String + variable
Echo ' ads$c ';//String asd$c $c not 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 multi-Line output method
Echo <<<end
This uses the ' Here Document ' syntax to output
End;
Output shorthand
<?php echo $a;? > <?= $a?>


Copy Code code as follows:

<?php
echo "Hello World";

echo "This spans
Multiple lines. The newlines would be
Output as the "";

echo "This spans\nmultiple lines. The newlines would be\noutput as a. ";

echo "Escaping characters is done \" like This\ "."

Can use variables inside of a 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
Echo ' foo is $foo '; Foo is $foo

If you are not using the are 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's here, document Terminator must appear on a
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 would work:
($some _var)? print ' true ': print ' false '; The print is also a construct, but
It behaves like a function, so
It may is used in the context.
Echo $some _var? ' True ': ' false '; Changing the statement around
?>

The following is a description of the official manual:
Definition and Usage
Definitions and usage
The Echo () function outputs one or more strings.
The Echo () function works by outputting one or more strings.
Syntax
Grammar
Echo (Strings)
Parameter parameter Description description
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
Tips and attention points
The note:the Echo () function is isn't actually a function, so you are not required to use parentheses with it. However, if you are want to pass the than one parameter to echo (), using parentheses would generate a parse error.
Note: the Echo () function is not a function in real sense, so you don't have to use it necessarily. If you want to pass more than one argument to the Echo () function, then using the parentheses "()" will produce an error.
Tip:the Echo () function is slightly faster than print ().
Tip: the Echo () function is equivalent to a simplified version of the print () function.
Tip:the Echo () function has the following shortcut syntax. Example 5.
Tip: the Echo () function contains the following simple wording. See in detail: Case 5.
Example 1
Case 1
Copy Code code 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 would be:
The above code will output the following result:
Who ' s Kai Jim? Who ' s Kai Jim? I don ' t know!

Example 2
Case 2
Copy Code code as follows:

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

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

Example 3
Case 3
Copy Code code as follows:

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

The output of the code above would be:
The above code 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 quotes (') and double quotes ("). Single quotes will output the variable name, not the value of the variable:
Copy Code code as follows:

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

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

Example 5
Case 5
Shortcut syntax:
Shorthand (shortcut) syntax:
Copy Code code as follows:

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