0

I am parsing a file to put its content into a database.

I test every line, if its content should ignored or handled, using substring on the first four characters.

My snippet is ..

$inputLine = 'Baseline 100%T,,...,,208a,,208b,,Leerfilter,';

$check = substr($inputLine, 0, 4);

var_dump($check)

My output from var_dump is:

string(4) "B"

Which is not what I expected. I expected "Base" as output but it tells me having a string containing four characters and its content is just "B".

The input is from a normal text file, like hundreds before of fine working files of the same kind and format which has been successfully parsed before.

Has anyone an idea what it means

string(4) "B"

Thanks in forward.

dlg_
  • 307
  • 4
  • 11
  • are there non-printing characters contained in the string? maybe your encoding is utf-32? you should read about multibyte-strings in php – Psi Aug 23 '22 at 14:42
  • Time to learn about NON-printable characters. – u_mulder Aug 23 '22 at 14:43
  • [It should print `Base`](https://3v4l.org/JIvD9), so I'm going to guess you have some invisible characters at the beginning of the string. – aynber Aug 23 '22 at 14:44
  • When I copy & paste that code if gives "string(4) Base" as expected. Check your encoding. Elsewise do a `$check = mb_substr($inputLine, 0, 4);` – Markus Zeller Aug 23 '22 at 14:44
  • Thanks for your suggestions. I opened the file in a hex editor and found three non printed dots leading my string. After removing this, everything worked fine. – dlg_ Aug 23 '22 at 15:32

0 Answers0