0

我有一个 wiki 网站 (MediaWiki),我需要从每个 wiki 文章页面的第一行中提取一些纯文本。每个 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

1

尝试这个:

$parts = explode("'''",$text,3);
$part_you_want = $parts[1];

这比使用正则表达式便宜得多,并且希望也能减少混乱。

于 2013-04-22T21:05:35.383 回答
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 回答