I have read, that b in front of something means binary.
I am receiving a text field from MS DB, column type is CLOB.
I am using Laravel and when I die dump (dd()) I see:
b"""
My big text
"""
If I create simple string and dd() it I see:
"My big text"
The problem is that json_encode() returns false on this b-String, but everything fine with simple string.
Could you please tell me how can I make it a simple string?
P.S. I have tried unpack() -> unsuccess
EDIT: actually json_encode() not related to this binary string. It was failing cause of non utf8 symbol. I see ...(22:45 – 0:15 CEST)..., but when I do utf8_decode($text), I see ...(22:45 ? 0:15 CEST)... and if I try to json_encode() now, it's works perfect.
PHP does not have "binary" and "non-binary" strings. It just has strings, and they're always "binary", as they're just acting like byte arrays. The b prefix is added by the Symfony VarDumper component as a sign that the string is not valid UTF-8. Arguably UTF-8 should be the one and only sensible encoding in use today, and apparently Symfony goes so far as to declare anything else as "binary", i.e. atypical text.
That is also the reason why your json_encode failed.
FWIW, b was a proposed forward compatibility prefix to prepare PHP code for PHP 6, which was supposed to have very Python-like binary strings and Unicode strings. Only PHP 6 never happened and the b prefix still does nothing. Symfony seems to have gone all out and adopted the b and """ conventions from Python nonetheless.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With