在 Netbeans 7.0.1 中向 .css 文件添加 php 语法突出显示
我刚刚发现可以通过添加
AddType application/x-httpd-php .css
到 .htaccess 文件来将 php 添加到 css 文件中。
然后添加
<?php header ("Content-type: text/css"); ?>
到项目中的所有 css 文件。
很多人不喜欢这个,因为它脱离了样式表的含义,但是它非常有用,例如我编写了一个简单的函数:
function linear_gradient($from, $to)
{
return "background:$from;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='$from',endColorstr='$to');background:-webkit-gradient(linear,left top,left bottom,from($from),to($to));background:-moz-linear-gradient(top,$from,$to);";
}
只需从 css 调用该函数就可以给我一个跨浏览器渐变。非常有用!
无论如何,问题是,netbeans 没有像在 css 文件中那样突出显示 php 语法,并且我收到大量错误,例如“无效内容”和“意外符号”等。
有谁知道如何更改语法突出显示 .css 文件将支持 php 和 css?
(很像 .php 文件如何支持 php 和 html)
谢谢
I've just found out that php can be added to css files by adding
AddType application/x-httpd-php .css
to the .htaccess file.
You then add
<?php header ("Content-type: text/css"); ?>
to all css files in the project.
Many people won't like this because it takes away from the meaning of style sheets, and blah blah blah however it is very useful for example I wrote a simple function:
function linear_gradient($from, $to)
{
return "background:$from;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='$from',endColorstr='$to');background:-webkit-gradient(linear,left top,left bottom,from($from),to($to));background:-moz-linear-gradient(top,$from,$to);";
}
That gives me a cross browser gradient just by calling the function from css. Very usefull!
Anyway, The Problem is, netbeans doesn't highlight the php syntax like it should do in the css file and I get a huge amount of errors like "Invalid content" and "Unexpected symbol" etc etc.
Does anybody know how to alter syntax highlighting so .css file will support php AND css?
(Much like how .php files support php and html)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您的 CSS 文件具有
.css
扩展名,Netbeans 会将其视为 CSS 文件。按照惯例,CSS 文件不包含 PHP 代码(您不会经常看到它),因此我认为您无法让 Netbeans 相信您编写的内容是“ok”。您可以忽略这些错误。 Netbeans 不会,但它是一个软件,而不是一个婴儿。
Since your CSS files have the
.css
extension, Netbeans will treat it like a CSS file. By convention, CSS files don't contain PHP code (you don't see it very often), so I don't think you can convince Netbeans that what you wrote is "ok".You could just ignore those errors. Netbeans won't, but it's a piece of software, not a baby.
PHP类外可以注释。
“echo $foo”会为 NetBeans 生成错误,但不会终止语法突出显示(我使用的是 NetBeans 7.1.2)。
PHP out of class can be commented.
"echo $foo" generates an error for NetBeans but doesn't kill syntax highlighting (I'm using NetBeans 7.1.2).