PHP-CSS-Parser icon indicating copy to clipboard operation
PHP-CSS-Parser copied to clipboard

Some characters are changed after render.

Open satalways opened this issue 9 years ago • 9 comments

Hi, I am facing problem about characters ...

.glyphicon-shopping-cart:before{content:"\e116"}

are converted into

.glyphicon-shopping-cart:before {content: "î„–";}

satalways avatar Jul 21 '15 12:07 satalways

This is a bug.

Currently, all string escapes are parsed and represented in the charset specified. Since you probably did not specify a charset either in the parser settings or the source CSS (via @charset), utf-8 is used. On the bright side, this means the character can be fully represented but it also means the file must be opened/served in utf-8.

The fix would be as follows:

  • Sabberworm\CSS\Value\String values should always be parsed internally as unicode and not converted to the source encoding (only from the source encoding).
  • There should be a formatter option to decide which encoding to use for outputting.
  • There should be a formatter option to decide when to output unicode escapes (always, only_when_necessary (if the destination charset can’t handle the character), all_beyond_bmp, all_beyond_ascii).

sabberworm avatar Jul 22 '15 07:07 sabberworm

Can you please provide snippet/sample ... Thanks.

satalways avatar Jul 22 '15 07:07 satalways

A snippet for what?

sabberworm avatar Jul 22 '15 07:07 sabberworm

Snippet for changing character set or you will fix it in future.. ?

satalways avatar Jul 22 '15 07:07 satalways

Put,@charset latin1 or whichever your character set is at the top of the file. But as I said it's a bug which I have to fix because if \e116 is not representable in said character set, just setting it won't work.

sabberworm avatar Jul 22 '15 07:07 sabberworm

The only fix that will certainly work is using some utf-encoding all the way.

sabberworm avatar Jul 22 '15 07:07 sabberworm

I'm having this same problem. How do I set the utf-8 encoding?

neel-pu avatar Apr 14 '16 08:04 neel-pu

I guess this should be resolved by #116

skodak avatar Aug 21 '16 08:08 skodak

I use FontAwesome and i have the same problem! What can i do to fix it ?

$oCssParser = new Sabberworm\CSS\Parser('.a:after{content:"\f2da"}');
$oCssDocument = $oCssParser->parse();
echo $oCssDocument;

Result:

PHP notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed
.a:after {content: "";}

EMDM45 avatar Nov 17 '18 15:11 EMDM45