PHP 8.5.0 Alpha 1 available for testing

Voting

: one minus zero?
(Example: nine)

The Note You're Voting On

Aidan Kehoe <php-manual at parhasard dot net>
21 years ago
The fastest way I've found to check if something is valid UTF-8 is
<?php
if (iconv('UTF-8', 'UTF-8', $input) != $input) {
/* It's not UTF-8--for me, it's probably CP1252, the Windows
version of Latin 1, with directed quotation marks and
the Euro sign. */
}
?>.
The iconv() C library fails if it's told a string is UTF-8 and it isn't; the PHP one doesn't, it just returns the conversion up to the point of failure, so you have to compare the result to the input to find out if the conversion succeeded.

<< Back to user notes page

To Top