2

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

PHP out of class can be commented.

/*<?php $foo='block' ?>*/
.class{
  display: <?php echo $foo ?>;
}

"echo $foo" generates an error for NetBeans but doesn't kill syntax highlighting (I'm using NetBeans 7.1.2).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.