PHP-CSS-Parser
PHP-CSS-Parser copied to clipboard
Some characters are changed after render.
Hi, I am facing problem about characters ...
.glyphicon-shopping-cart:before{content:"\e116"}
are converted into
.glyphicon-shopping-cart:before {content: "î„–";}
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
).
Can you please provide snippet/sample ... Thanks.
A snippet for what?
Snippet for changing character set or you will fix it in future.. ?
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.
The only fix that will certainly work is using some utf-encoding all the way.
I'm having this same problem. How do I set the utf-8 encoding?
I guess this should be resolved by #116
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: "";}