Re: Help needed with mb_convert_encoding()
| From: | Flavio Kenji Yanai | Date: | Wed, 28 May 2014 09:56:48 +0000 |
| Subject: | Re: Help needed with mb_convert_encoding() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-323366@lists.php.net to get a copy of this message | ||
I don't test it ...
$utf8_str = utf8_decode($original_str);
if (!substr_cmp($utf8_str,$original_str,length($original_str)){
echo "equal, valid utf8";
}
else {
echo "not equal , non valid utf8 input";
}
2014-05-28 6:03 GMT-03:00 Alain Williams <addw@phcomp.co.uk>:
> 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.
>
> Thanks in advance
>
> <?php
> mb_internal_encoding("UTF-8");
>
> // I have tried many lines like the 2 below
> // (comment out one or the other)
> mb_substitute_character((int)0x3013);
> mb_substitute_character((int)63); // '?' is ascii 63
>
> // \xC0\xBC is invalid UTF-8 - over long encoding, should be \x3C
> $input = "a bad angle bracket \xC0\xBC here";
> $valid = mb_convert_encoding($input, "UTF-8", "UTF-8");
>
> // I always find 2 spaces between 'bracket' and 'here'
> echo "valid='$valid'\n";
>
>
> --
> Alain Williams
> Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT
> Lecturer.
> +44 (0) 787 668 0256 http://www.phcomp.co.uk/
> Parliament Hill Computers Ltd. Registration Information:
> http://www.phcomp.co.uk/contact.php
> #include <std_disclaimer.h>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Flávio Kenji Yanai (Toccos)