2

「[]」自体を含む [...] 内の文字列を削除する必要があります。このサイトから解決策を探してみました。preg_replace で何かを試す必要があるという手がかりはありますが、私には専門的すぎるようです。

例えば ​​:

[gallery ids="92,93,94,95,96,97,98,99,100" orderby="rand"] Description The thirty-two storey resort condominium in Phuket, located Just 150m from Patong beach where choices of activities, water sp 

サンプル テキストから[gallery ids="92,93,94,95,96,97,98,99,100" orderby="rand"]を削除する必要があります。そして、常に[gallery ids="で始まります。

提案してください。

4

1 に答える 1

7

これを試して:

$string = '[gallery ids="92,93,94,95,96,97,98,99,100" orderby="rand"] Description The thirty-two storey resort condominium in Phuket, located Just 150m from Patong beach where choices of activities, water sp ';
$string = preg_replace('/\[gallery ids=[^\]]+\]/', '', $string);

壊す:

\[gallery ids=で始まる部分文字列を探します[gallery ids=

[^\]]+\]]あなたが到達するまでではない1つ以上の文字に一致する]

次に、一致した部分全体を''何も置き換えず、新しい文字列を作成します。

于 2013-03-03T16:02:25.600 に答える