Trim unicode whitespace in PHP 5.2

前端 未结 7 1500
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 09:17

How can I trim a string(6) \" page\", where the first whitespace is a 0xc2a0 non-breaking space?

I\'ve tried trim() and preg_match(\'

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-01 09:54

    PCRE unicode properties properties can be used to achieve this

    Here is the code that I played with and seems to do what you want:

    Result

    [~]> php e.php
    string(6) "#page#"
    

    Explanation:

    \p{xx} a character with the xx property \P{xx} a character without the xx property

    If xx has only one character, then {} can be dropped, e.g. \p{Z} is the same as \pZ

    Z stands for all separators, C stands for all "other" characters (for example control characters)

提交回复
热议问题