|
Q:PHP 的开始和结束标志
A:一个令人混淆的东西,到底是用”〈?php ?〉“还是”〈? ?〉“来标志php代码?答案原来在php文档的最前面。
Example #2 PHP Opening and Closing Tags
1. 〈?php echo ’if you want to serve XHTML or XML documents, do like this’; ?〉
2. 〈script language=“php“〉
echo ’some editors (like FrontPage) don\’t like processing instructions’;
〈/script〉
3. 〈? echo ’this is the simplest, an SGML processing instruction’; ?〉
〈?= expression ?〉 This is a shortcut for “〈? echo expression ?〉“
4. 〈% echo ’You may optionally use ASP-style tags’; %〉
〈%= $variable %〉 This is a shortcut for “〈% echo $variable %〉“While the tags seen in examples one and two are both always available, example one is the most commonly used, and recommended, of the two.
Short tags (example three) are only available when they are enabled via the short_open_tag php.ini configuration file directive, or if php was configured with the --enable-short-tags option.
ASP style tags (example four) are only available when they are enabled via the asp_tags php.ini configuration file directive.
Note: Using short tags should be avoided when developing applications or libraries that are meant for redistribution, or deployment on PHP servers which are not under your control, because short tags may not be supported on the target server. For portable, redistributable code, be sure not to use short tags.
|
|