Don't try to randomly call any functions. PHP does not detect any encoding. Every character is simply a sequence of bytes, with "zero" bytes having no special meaning. So essentially there shouldn't be any reason for the failure you are observing.
Do some debugging. var_dump($_REQUEST)
would be in order, preferrably in a simplified testcase with only one value. If you need to detect any non-printable bytes, use echo urlencode($value)
to get to the hex values quickly - but this is only for debugging! It won't help with the issue, i.e. url-encoding the value will not make it usable again for your application (the same applies to using htmlspecialchars()
, which is not helping anything).
Also dump $val
in your code. If it really is empty, then urlencode() or htmlspecialchars() will not change it, the error is occurring before that.
Your question yet does not reveal any more info, so please do these value dumps - and if you cannot figure it out yourself then, update your question with these dumps for all to see.