简体   繁体   English

PHP - WAMP服务器

[英]PHP - WAMP server

I have a problem with WAMP server (2.1); 我有WAMP服务器(2.1)的问题; I have some php files that contain php statements between 我有一些PHP文件,其中包含PHP语句

<? statements ?> 

and the browser don't interprets the code. 并且浏览器不解释代码。 If I use : 如果我使用:

<?php statements ?>

everything works ok. 一切正常。

Any idea how to fix it. 知道如何解决它。 Thank you. 谢谢。

Whether you should or should not use short tags is debatable. 是否 应该使用短标签是值得商榷的。 I personally do not and I don't recommend it. 我个人不这样做,我不推荐它。 That being said — with WAMPServer 2 you can: 话虽如此 - 使用WAMPServer 2你可以:

  1. Click on the wampserver tray icon. 单击wampserver托盘图标。
  2. Go to PHP . 转到PHP Then PHP Settings 然后PHP设置
  3. Click short open tag . 点击短开标签 (When it's on it will have a checkmark next to it.) (当它打开时,旁边会有一个复选标记。)

Using the tray icon (lower right — next to the clock) is the easiest, least error prone way to make any changes in WAMPServer 2+. 使用托盘图标(右下角 - 时钟旁边)是在WAMPServer 2+中进行任何更改的最简单,最不容易出错的方法。

As kieran said: 正如基兰所说:

This is a good thread on why you shouldn't use short tags: Are PHP short tags acceptable to use? 这是一个很好的线程,为什么你不应该使用短标签: PHP短标签是否可以使用?

If you decided to used them , add in your php.ini: 如果您决定使用它们 ,请添加您的php.ini:

short_open_tag=On

Documentation for php.ini directives php.ini指令的文档


Be carefull, in a wamp installation, php.ini can be found at multiple locations: 小心,在wamp安装中,php.ini可以在多个位置找到:

wamp\bin\apache\Apache<version>\bin\php.ini
wamp\bin\php\php<version>\php.ini

Accessing the php.ini from the wamp menu (left click on wamp tray icon / php / php.ini ) opens the php.ini of the current apache version. 从wamp菜单访问php.ini(左键单击wamp tray icon / php / php.ini )打开当前apache版本的php.ini。

This is a good thread on why you shouldn't use short tags: Are PHP short tags acceptable to use? 这是一个很好的线程,为什么你不应该使用短标签: PHP短标签是否可以使用?

Don't use <? statements ?> 不要用<? statements ?> <? statements ?> - short tags are evil! <? statements ?> - 短标签是邪恶的!

You can change it in the php.ini file but it even says in that file not to use them... 你可以在php.ini文件中更改它,但它甚至在该文件中说不要使用它们...

This directive determines whether or not PHP will recognize code between tags as PHP source which should be processed as such. 该指令确定PHP是否将标记之间的代码识别为PHP源,应该如此处理。 It's been recommended for several years that you not use the short tag "short cut" and instead to use the full tag combination. 多年来一直建议你不要使用短标签“捷径”,而是使用完整的标签组合。 With the wide spread use of XML and use of these tags by other languages, the server can become easily confused and end up parsing the wrong code in the wrong context. 随着XML的广泛使用以及其他语言对这些标记的使用,服务器很容易混淆并最终在错误的上下文中解析错误的代码。 But because this short cut has been a feature for such a long time, it's currently still ; 但由于这种捷径已经成为这么长时间的一个特征,它目前仍然存在; supported for backwards compatibility, but we recommend you don't use them. 支持向后兼容性,但我们建议您不要使用它们。 Default Value: On ; 默认值:开; Development Value: Off ; 发展价值:关闭; Production Value: Off ; 产值:关; http://www.php.net/manual/en/ini.core.php#ini.short-open-tag http://www.php.net/manual/en/ini.core.php#ini.short-open-tag

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM