0

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,

Dennis
  • 79
  • 11

3 Answers3

6

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; ?>";
Dave
  • 5,108
  • 16
  • 30
  • 40
  • How so basic of me... i had done the first example you provided, but DreamWeaver tells me it is not correct (of course - gotta change editors some day), so I had backed out. Thanks Dave. – Dennis Aug 21 '18 at 19:48
0

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...

0

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?

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Dave gave the right solution. I did not want to add the \ before because I'm having the client copy the unicode from the Font-Awesome 5 website directly. The website does not include the \ before when you copy the unicode. – Dennis Aug 21 '18 at 19:52