Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't convert 'binary' string to 'regular' string

Tags:

string

php

binary

I'm reading from a file through 'file_get_contents'. After exploding the content, one of the elements is presented this way when I dump it:

dd($myVariable);

b"Crédito"

I've read on the internet that this is some kind of 'binary' string, related to a PHP version 6 that never existed. But I simply can not find a way to convert it to a 'regular' string.

I thought they were somehow equivalent, but I can't even use it to compare to another string. For example, none of these will ever return true:

if ($myVariable == "Crédito") 
if ($myVariable === "Crédito")
if ($myVariable == b"Crédito")
if ($myVariable == (binary)"Crédito")

How can I convert it to a regular string?

like image 590
gabpalves Avatar asked Sep 01 '26 03:09

gabpalves


1 Answers

For me, utf8_encode helped. hope it will help someone else also

utf8_encode($string)
like image 175
Emtiaz Zahid Avatar answered Sep 02 '26 15:09

Emtiaz Zahid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!