18        $string = trim($string);
 
   23        $subtags = explode(
'-', $string);
 
   24        $num_subtags = count($subtags);
 
   26        if ($num_subtags == 0) { 
 
   31        $length = strlen($subtags[0]);
 
   36                if (!($subtags[0] == 
'x' || $subtags[0] == 
'i')) {
 
   42                if (!ctype_alpha($subtags[0])) {
 
   44                } elseif (!ctype_lower($subtags[0])) {
 
   45                    $subtags[0] = strtolower($subtags[0]);
 
   52        $new_string = $subtags[0];
 
   53        if ($num_subtags == 1) {
 
   58        $length = strlen($subtags[1]);
 
   59        if ($length == 0 || ($length == 1 && $subtags[1] != 
'x') || $length > 8 || !ctype_alnum($subtags[1])) {
 
   62        if (!ctype_lower($subtags[1])) {
 
   63            $subtags[1] = strtolower($subtags[1]);
 
   66        $new_string .= 
'-' . $subtags[1];
 
   67        if ($num_subtags == 2) {
 
   72        for (
$i = 2; 
$i < $num_subtags; 
$i++) {
 
   73            $length = strlen($subtags[
$i]);
 
   74            if ($length == 0 || $length > 8 || !ctype_alnum($subtags[
$i])) {
 
   77            if (!ctype_lower($subtags[
$i])) {
 
   78                $subtags[
$i] = strtolower($subtags[
$i]);
 
   80            $new_string .= 
'-' . $subtags[
$i];
 
An exception for terminatinating execution or to throw for unit testing.
Validates the HTML attribute lang, effectively a language code.
validate($string, $config, $context)
Base class for all validating attribute definitions.