1
4

3 に答える 3

8

You're probably having the special characters in entity form, i.e. ® is really ® in your string. So it's not seen by the replacement operation.

To fix this, you could filter for the &SOMETHING; substring, and remove them. There might be built-in methods to do this, perhaps html_entity_decode.

于 2010-01-04T15:22:56.137 に答える
4

上記の文字のみを置き換えたい場合は、

$cleaned = str_replace(array('®','™','®','™', ":", "'"), '', $string);

通常、通常の文字列置換メソッドはより高速であり、正規表現エンジンのパターン マッチング機能を必要とする置き換えたい例はありません。

コメントによる編集: 文字パターンを置き換える必要がある場合(自分で与えた解決策で示されているように)、正規表現は実際により適切で実用的です。

さらに、McD は、そのスローガンが公開 Web サイトで使用されている場合、両方のシンボルを配置する必要があると確信しています。

于 2010-01-04T15:40:55.990 に答える
0

® は®、™ は™です。そのため、事前に
パターンに従うものはすべて削除する必要があります。&[#0-9a-z]+;

$input = "Remove all ™ and ® symbols, please.";
$string = preg_replace("/&[#0-9a-z]+;/i", "", $input);
于 2010-01-04T15:35:24.083 に答える