Re: Help needed with mb_convert_encoding()
| From: | Christoph Becker | Date: | Wed, 28 May 2014 14:04:43 +0000 |
| Subject: | Re: Help needed with mb_convert_encoding() | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-323370@lists.php.net to get a copy of this message | ||
Alain Williams wrote:
> On Wed, May 28, 2014 at 02:12:32PM +0200, Christoph Becker wrote:
>> Alain Williams wrote:
>>
>>> I am trying to use this to validate input that is supposed to be UTF-8 and to
>>> replace any bad characters with something - '?' would do.
>>>
>>> I have the test program below. No matter what I try to give as an argument to
>>> mb_substitute_character() it always removes the bad input sequence, I would like
>>> to replace it.
>>
>> Have you considered using htmlspecialchars($input, ENT_SUBSTITUTE,
>> 'UTF-8') instead of mb_substitute_character()?
>
> OK-ish -- thanks.
>
> * ENT_SUBSTITUTE is only available from PHP 5.4 - my production machine is PHP 5.3.3 (CentOS)
>
> * It also munges & < > -- but I can undo that with htmlspecialchars_decode()
>
> * I need to replace the Unicode Replacement Character ("\xEF\xBF\xBD") with a
> '?' (easy)
>
> * If I give it an over long character encoding (I tested "\xC0\xBC") it replaces
> each byte with a '?' - so I get two of them.
>
> It would be nice to get mb_substitute_character() working.
You might be out of luck with PHP 5.3, see <http://3v4l.org/I3mEd>.
--
Christoph M. Becker