src/XML/Util.php
function isValidName($string)
    {
        // check for invalid chars
        if (!preg_match('/^[[:alpha:]_]$/', $string{0})) {
            return XML_Util::raiseError('XML names may only start with letter '
                . 'or underscore', XML_UTIL_ERROR_INVALID_START);
        }

        // check for invalid chars
        if (!preg_match('/^([[:alpha:]_]([[:alnum:]\-\.]*)?:)?[[:alpha:]_]([[:alnum:]\_\-\.]+)?$/',
            $string)
        ) {
            return XML_Util::raiseError('XML names may only contain alphanumeric '
                . 'chars, period, hyphen, colon and underscores', 
                XML_UTIL_ERROR_INVALID_CHARS);
        }
        // XML name is valid
        return true;
    }
function isValidName($string)
    {
        // check for invalid chars
        if (!preg_match('/^[[:alpha:]_]$/', $string{0})) {
            return XML_Util::raiseError('XML names may only start with letter '
                . 'or underscore', XML_UTIL_ERROR_INVALID_START);
        }

        // check for invalid chars
        if (!preg_match('/^([[:alpha:]_]([[:alnum:]\-\.]*)?:)?[[:alpha:]_]([[:alnum:]\_\-\.]+)?$/',
            $string)
        ) {
            return XML_Util::raiseError('XML names may only contain alphanumeric '
                . 'chars, period, hyphen, colon and underscores', 
                XML_UTIL_ERROR_INVALID_CHARS);
        }
        // XML name is valid
        return true;
    }
check, whether string is valid XML name

<p>XML names are used for tagname, attribute names and various
other, lesser known entities.</p>
<p>An XML name may only consist of alphanumeric characters,
dashes, undescores and periods, and has to start with a letter
or an underscore.</p>

<code>
require_once 'XML/Util.php';

// verify tag name
$result = XML_Util::isValidName('invalidTag?');
if (is_a($result, 'PEAR_Error')) {
print 'Invalid XML name: ' . $result->getMessage();
}
</code>

@param string $string string that should be checked

@return mixed true, if string is a valid XML name, PEAR error otherwise
@access public
@static
@todo support for other charsets
@todo PEAR CS - unable to avoid 85-char limit on second preg_match