Safe encoding conversion in PHP

I've got a huge trouble with encoding conversion.

I'm trying to convert file content from "CP852, CP1250, ISO-8859-2", etc. to UTF-8.

The issues happens, when encoding is differs from what system expects what in theory is acceptable, but after conversion I receive question marks, different symbols or whole text removal.

I made small test:

/** @var data string in "ISO-8859-1 encoding Danish" */
// $data = 'ø, æ, å';
/** @var data string in "ISO-8859-2 encoding Polish" */
$data = 'Ł Ż ł Śóś';

foreach(mb_list_encodings() as $chr){
    debug(mb_detect_encoding($data, $chr, true));
    debug(mb_convert_encoding($data, 'UTF-8', $chr)." : ".$chr);
}

So for polish letters I receive: ISO-2022-KR, CP950, BIG-5, ISO-8859-15, ISO-8859-14, ISO-8859-13. ISO-8859-10-ISO-8859-1, etc. So mb_detect_encoding returns a lot "false" and "encoding" names, but only one of them returns correct data after conversion - "ISO-8859-2", but if I limit allowed encoding list and pass content in CP1250, in return I get that ISO-8859-2, UTF-8. is correct, but data after conversion is broken.

Can someone explain, how to avoid issues with different encoding and always correctly convert text to UTF-8 or a chance to detect encoding which won't broke data?