GenesisBits:
私はそうのように文字列を持っています:
[[EARTH]] [[Machine]] [[Monster Card|monsters]]
If this card is [[Link Summon]]ed: You can [[Add a card|add]] 1 "[[Ancient Gear]]" monster or 1 "[[Geartown]]" from your [[Main Deck|Deck]] to your [[hand]]. You can [[target]] 1 [[Spell Card|Spell]]/[[Trap Card|Trap]] you [[control]] and 1 [[face-up]] monster your opponent controls; [[destroy]] that card you control, and if you do, change that opponents monsters [[ATK]]/[[DEF]] to 0 until the end of this [[turn]]. You can only use each [[effect]] of "Ancient Gear Ballista" [[once per turn]].
私はすべての角括弧を削除するために次のコードを使用しています:
$stringout = str_replace(array('[[',']]'),'',$stringout);
ブラケットが含まれている場合ただし、|
文字を、私はこの文字の後にテキストのみを維持する必要があります。
このSOから:
[[Monster Card|monsters]]
これに:
monsters
私はこれを試してみました:
$stringout = str_replace(array('[[|',']]'),'',$stringout);
CBroe:
本当に多くにpreg_replaceと正規表現のために仕事をし、単純な文字列の置換より。
$result = preg_replace('#\[\[(?:[^\]]*\|)?([^\]]*)\]\]#', '$1', $input);
(?:[^\]]*\|)?
可能にする非捕捉基である任意 ...|
の部分。オプション、それはので、$1
常にどちらかの休息ないだろう第二部、を参照します後つまり、もしくは間の完全なコンテンツを[[…]]
何があった場合、|
。