将斜杠插入CSS

I'm trying to add font-awesome unicode into my CSS using PHP. I'm trying to achieve: content: "\f001"; for example.

I'm able to add the "f001" part wihout issue, but the starting "\" is causing me headaches.

With PHP, I'm unable to echo the \ character before without adding a space after it.

I've searched for a solution everywhere but cannot overcome this.

Here is an example where I'm displaying the value:

content: "<?php echo $bkpk_fa_code; ?>";

That will produce the unicode value so the result will be:

content: "f001';

But of course, I need the \ before it.

I've tried many different variations to get the desired output of "\f001" with no luck.

Can anyone pride the solution to do this?

Best Regards,

Simply put the backslash outside of the PHP echo.

content: "\<?php echo $bkpk_fa_code; ?>";

If you want to use the backslash inside of the echo you may escape it.

content: "<?php echo '\\' . $bkpk_fa_code; ?>";

this will echo "\f001";

<?php $bkpk_fa_code='f001';?>

content: "\<?php echo $bkpk_fa_code; ?>";

alternately

content: "<?php echo '\\'.$bkpk_fa_code; ?>";

ohh..dave and I am editing answer with few seconds difference...

You need to make sure that the variable contains the backslash:

$bkpk_fa_code = '\f001';

Don't use double quotes around the string, as backslash is treated as an escape prefix inside double quotes and would have to be doubled. See What is the difference between single-quoted and double-quoted strings in PHP?