在CSS中的PHP不起作用

I'm trying to use php inside my css but server return php-code as is <style>p{background: url(<?php echo hello;?>)};</style>

I see url(<?php echo hello;?>) in my inline style with browser console. It doesn't matter do I place text/css header inside the code or not, quoted or double-quoted the php section.

But this style work properly on another server. Maybe there is any setting that doesn't allow use php this way?

It seems that the problem is that you're trying to put php code into a .css file and your server is not configured to run php from this file type.

If you're using Apache, you can try to add this line into your .htaccess file (create one in the root if you don't have it)

AddType application/x-httpd-php .css

However, note that this action may cause some security issues.

If you give your CSS file a .php extension (e.g. style.php) you can include PHP code in it. You may also want to send a CSS MIME type in the header, e.g.:

header( 'Content-Type: text/css' ); 

I think you are doing the thing wrong way with a wrong syntax.

$hello= "'img/example.jpg'";
<style>p{background: url(<?php echo $hello;?>)};</style>

You are missing the quotes here.