0

私はこのような文字列を持っていますが、含めたくありません[gallery columns="7"]。正規表現を使用してそれを行うにはどうすればよいですか。新しい行は大丈夫です。

[gallery columns="7"]

For sale house and lot in Cabancalan Mandaue

lot area 300 sqm
floor area 220 sqm
4 bedrooms 4 toilet and bath

with big lawn and open space

inside subdivision


for more info please contact 0932-219-4469
4

1 に答える 1

0

この正規表現はあなたのために働くはずです:

$newContent = preg_replace('/\[gallery [a-z0-9\_\-\s=\’"]+\]\s*/i', '', $oldContent);

次のようなスニペットの出現をすべて削除します(後続の空白を含む)。

[gallery columns="7"]
[gallery height="250" width='auto' ]
[gallery rows="2" columns="4" auto-adjust="false" ]

preg_replaceドキュメント: http: //php.net/manual/en/function.preg-replace.php

うまくいけば、これはあなたの問題を解決します。

編集:これは、角かっこ内のリンクやその他のものも削除します。

$newContent = preg_replace('/\[gallery [^\]]+\]\s*/i', '', $oldContent);
于 2012-09-26T07:48:10.017 に答える