From Joomla! Documentation

< API16:JString
Revision as of 16:48, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.


Tests whether a string complies as UTF-8. This will be much faster than utf8_is_valid but will pass five and six octet UTF-8 sequences, which are not supported by Unicode and so cannot be displayed correctly in a browser. In other words it is not as strict as utf8_is_valid but it's faster. If you use is to validate user input, you place yourself at the risk that attackers will be able to inject 5 and 6 byte sequences (which may or may not be a significant risk, depending on what you are are doing) valid

[Edit Descripton]



static compliant($str)
Parameter Name Default Value Description
$str UTF-8 string to check


boolean TRUE if string is valid UTF-8

Defined in



jimport( 'joomla.utilities.string' );

Source Body

public static function compliant($str)
        if (strlen($str) == 0) {
                return TRUE;
        // If even just the first character can be matched, when the /u
        // modifier is used, then it's valid UTF-8. If the UTF-8 is somehow
        // invalid, nothing at all will match, even if the string contains
        // some valid sequences
        return (preg_match('/^.{1}/us',$str,$ar) == 1);

[Edit See Also] SeeAlso:JString/compliant


<CodeExamplesForm />