Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
すべての制御文字を削除して、改行 ( U+2028) 文字を除外する方法は?
U+2028
preg_replace('/[\p{Cc}]/', '', $response);
http://uk.php.net/manual/en/regexp.reference.unicode.php
あなたは否定的な先読みを使うことができます:
/(?!\x{2028})\p{Cc}/u
また、Unicodeと一致するようにUTF8モードを有効にする必要があります。
二重否定を使用できます
preg_replace('/[^\P{Cc}\x{2028}]/u', '', $response);
\P{Cc}の否定です\p{Cc}
\P{Cc}
\p{Cc}
[^...]否定された文字クラスです
[^...]
したがって、制御文字ではなく、 ではないすべてのものに一致します\x{2028}。このようにして、定義済みの文字クラスから特定の文字を除外できます。
\x{2028}