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

前端 未结 9 1550
失恋的感觉
失恋的感觉 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:09

    This should give you roughly what you need [Assuming you are using Unicode]:
    (Note: This is completely untested.)

    [^\p{P}xX0-9][^mMlL\s]{2}[\w\p{P}0-9-]
    

    \p{P} is the syntax for Unicode Punctuation marks in PHP's regular expression syntax.

提交回复
热议问题