Saving data on a file issue


I have this


which is extracted from a server log

When I save this $data in a file using
file_put_contents(“data”, "$data

In my data file I have lines like these

? which could be the cause

Thank you

At a guess, I’d say this is a character encoding issue (these are commonly seen if you transfer between Linux and Windows systems).
Have a look into

Still no solution , really lost.

Are the odd characters being introduced from the log read or the file_put_contents?

Have you checked that data doesn’t contain any hidden characters (which come from character encoding differences)? It looks to me like the characters you’re seeing (^[0;10m^[39;49m) represent whitespace in the string, but without having access to the specifics of your problem, such as server setup, log file type, …, I can’t help any further.

before executing this
file_put_contents(“data”, "$data

I echo the data using this
echo “-$data-”;
and I receive this


which is correct .
If I save it on file , is all messed up .