How to check if string is a valid XML element name?

前端 未结 9 1548
失恋的感觉
失恋的感觉 2020-11-27 06:56

I need a regex or a function in PHP that will validate a string to be a good XML element name.

Form w3schools:

XML elements must follow these

9条回答
  •  长情又很酷
    2020-11-27 07:17

    if (substr(strtolower($text), 0, 3) != 'xml') && (1 === preg_match('/^\w[^<>]+$/', $text)))
    {
        // valid;
    }
    

提交回复
热议问题