1

私はいくつかのタイトルを持っています、例えば:

should? be fenêtre!

ﻟﻔﺮﻧﺴﻴﺔ-تعاني!!!

次のような特殊文字を削除するために使用できる正規表現:?、!、^

次のようなタイトルを取得する必要があります。

should-be-fenêtre

ﻟﻔﺮﻧﺴﻴﺔ-تعاني

私は試した

$name = preg_replace("~[\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+~", "-", $name);

しかし、私は得る

Warning: preg_replace(): No ending delimiter '~' found in

ありがとう

4

2 に答える 2

3

いくつかの正規表現を使用して、文字や数字以外のものをすべて取り除き、空白とダッシュの実行を1つのダッシュに凝縮することができます。

// Replaces every non-letter, non-digit with a dash
$str = preg_replace('/(?=\P{Nd})\P{L}/u', '-', $str);

// Replaces runs of whitespace and dashes with a single dash
$str = preg_replace('/[\s-]{2,}/u', '-', $str);
于 2013-02-04T20:53:05.307 に答える
0

これを試して:

$text = preg_replace("/(?![.=$'€%-])\p{P}/u", "", $text);

保持したいUnicode文字に一致するようにアサーションを変更するだけです。

于 2013-02-04T20:38:30.553 に答える