The use of PHP eot delimiters _php Tips

Source: Internet
Author: User
The end identifier must start with the first column of the row. Likewise, identifiers must follow the naming rules for any other label in PHP: They can only contain alphanumeric underlines and must begin with an underscore or non-numeric character.
Warning
It is important to note that the line containing the end identifier cannot contain any other characters, except that it may be a semicolon (;). This means, in particular, that the identifier cannot be indented, and that no spaces or tabs are allowed before and after the semicolon. It is also important to realize that the first character before the end identifier must be a line break defined in your operating system. For example, in the Macintosh system is \ r.
If this rule is broken so that the end identifier is not "clean," it will not be considered an end identifier, and PHP continues to look for it. If the appropriate end identifier cannot be found in this case, it will cause a syntax error that appears on the last line of the script.
Class members cannot be initialized with delimiter syntax. Replaces with another string syntax. Example 11-3. Illegal example
PHP code
<?php
class Foo {
Public $bar = <<<eot
Bar
EOT;
}
?>
The delimiter text behaves just like a double quote string, except that there are no double quotes. This means that you do not need to escape the quotation marks in the delimiter text, but you can still use the escape code listed above. Variables are expanded, but the same is true when expressing complex variables in the delimiter text as well as strings. Example 11-4. Delimiter String Example
PHP code
<?php
$str = <<<eot
Example of String
Spanning multiple lines
Using Heredoc syntax.
EOT;
/* More complex example, with variables. */
Class Foo
{
var $foo;
var $bar;
function foo ()
{
$this->foo = ' foo ';
$this->bar = Array (' Bar1 ', ' Bar2 ', ' Bar3 ');
}
}
$foo = new Foo ();
$name = ' myname ';
Echo <<<eot
The My name is "$name". I am Printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This is should print a capital ' a ': \x41
EOT;
?>
Note: The delimiter support is added in PHP 4.
How to output HTML code in PHP (EOT)
PHP code
<?php
Echo <<< EOT
<table width=80% border= "2" cellpadding= "3" cellspacing= "0" bordercolor= "#808080" >
<tr bgcolor= "#84A9E1" >
&LT;TD align= "center" >ClassID</td>
&LT;TD align= "center" >stuno</td>
&LT;TD align= "center" > Student name </td>
&LT;TD align= "center" > Parent name </td>
&LT;TD align= "center" > Parent Cell phone number </td>
</tr>
EOT;
?>

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.