Search code examples
phpsimplexmlprintf

PHP printf not printing, simplexml_load_string not parsing


I have some data that won't printf....

echo works, but not printf

There is data in the string, also simplexml_load_string won't parse the string.

There is some binary or invisible character that I cannot see and can't get the ordinal value for that is causing printf to fail as well as most other string functions in PHP.

Clearly this is an encoding issue, however, I don't know how to find out what it is so I can properly encode/decode it.

$string = getStringFromDatabase();
printf($string);

...

Nothing is displayed

...

No errors, No Warnings, No Nothing

Clearly there is data there, I know it's there if I loop over every single character, however, I don't where to go from there.

[UPDATE] This is weird because the ordinal value is outside of the typical ASCII range.

ord($buffer[$i]) = 1610

it is a combo of a DLE and LF characters. Not sure how it got there or why. Or what it was supposed to be, the data on either side is valid and the location for this is quite odd.

think <offending char here>0,000


Solution

  • The answer is a multi-byte character that is an bug from the runtime. You can work around it by finding chr(16) in your string and replacing it with an empty string (""). That is if you need it to work with s/v/printf functions.