0

私はウィキ Web サイト (MediaWiki) を持っており、各ウィキ記事ページの最初の行からプレーン テキストを抽出する必要があります。各 wiki 記事ページの最初の行には必要なテキストがありますが、テキストは wiki マークアップ タグ内にあります。たとえば、次のようになります。

$text = "Text that I DO NOT want '''Text that I do want, inside wiki tags''' text that I DO NOT want";

最初の行の終わりまでテキストを取得するための PHP 正規表現を見つけました。

if(preg_match("/^.*/", $text, $match)){
  echo "<br>This is the text in the first line of the wiki article page: ".$match[0];
}

/^.*/上記の式を PHP 正規表現と組み合わせて、 '''wiki タグ内のテキストのみを検索する必要があります。そして、私はこれを行うのに問題があります。誰かがこれで私を助けることができますか? また、一重引用符をエスケープするにはどうすればよい'''ですか?
ご助力いただきありがとうございます。

ピーター

4

2 に答える 2

0

これを試して:

$text = "Text that I DO NOT want '''Text that I do want, inside wiki tags''' text that I DO NOT want";
if(preg_match("/'''(.*)'''/", $text, $match)){
  echo "<br>This is the text in the first line of the wiki article page: ".$match[1];
}
于 2013-04-23T00:11:47.040 に答える