PHP echo Output String function detailed _php tutorial

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 $c 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 multi-Line output method
Echo << This uses the ' Here Document ' syntax to output
END;
Output shorthand
  


Copy CodeThe code is as follows:
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
Echo ' foo is $foo '; Foo is $foo

If you aren't 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 ' This ', ' string ', ' is ', ' 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
The here document Terminator must appear on 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
It behaves like a function, so
It is used in the this context.
Echo $some _var? ' True ': ' false '; Changing the statement around
?>

The following is a description of the official manual:
Definition and Usage
Definition 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. Specify one or more strings that need to be sent to the result
Tips and Notes
Tips and attention points
Note:the Echo () function is a function of actually a, so that is not the 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 ().
Tip: the Echo () function is equivalent to a simplified version of the print () function.
Tip:the Echo () function has the following shortcut syntax. See Example 5.
Tip: the Echo () function contains the following handy notation. See details: Case 5.
Example 1
Case 1
Copy CodeThe code is as follows:
$str = "Who's Kai Jim?";
Echo $str;
echo "
";
echo $str. "
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
Copy CodeThe code is as follows:
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
Copy CodeThe code is as follows:
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:
Copy CodeThe code is as follows:
$color = "Red";
echo "Roses is $color";
echo "
";
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:
Copy CodeThe code is as follows:

$color = "Red";
?>

Roses is



http://www.bkjia.com/PHPjc/321769.html www.bkjia.com true http://www.bkjia.com/PHPjc/321769.html techarticle Copy the 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, .....

  • Related Article

    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.