从 php 中的 mediawiki 标记中获取类别值
grab category value from mediawiki markup in php
我正在循环从 wiki 标记文本中检索类别值,无法使用 php
中的正则表达式匹配从标记中获取类别值
标记文本包含的类别值为
$input_wiki_markup = "
[[Category:Google]]
[[Category:Tricks]]
[[Category:Google Search]]
[[Category:Filters]]
[[Category:Search]]
[[Category:Tips]]";
这是我目前尝试过的方法
$matches = array();
if(preg_match("/\[\[(Category):(.+)*\]\]/i", $input_wiki_markup, $matches)){
print_r($matches);
}
这是输出
Array
(
[0] => [[Category:Google]][[Category:Tricks]][[Category:Google Search]][[Category:Filters]][[Category:Search]][[Category:Tips]]
[1] => Category
[2] => Google]][[Category:Tricks]][[Category:Google Search]][[Category:Filters]][[Category:Search]][[Category:Tips
)
但我正在尝试获取仅包含冒号后类别值的输出数组,即
Array
(
[0] => Google
[1] => Tricks
[2] => Google Searcg
)
以此类推
我应该对我的正则表达式进行哪些更改以仅获取 $mathces 数组中填充的类别值
或者我应该使用其他 php 函数而不是 preg_match 吗?
请注意,$input_wiki_markup
还包含 [[Categpry:xyz]]
标签周围的其他文本
你只需要 全部
$input_wiki_markup="
[[Category:Google]]
[[Category:Tricks]]
[[Category:Google Search]]
[[Category:Filters]]
[[Category:Search]]
[[Category:Tips]]
";
$matches = array();
if(preg_match_all("/\[\[(Category):(.+)*\]\]/i", $input_wiki_markup, $matches)){
print_r($matches);
}
输出:
Array
(
[0] => Array
(
[0] => [[Category:Google]]
[1] => [[Category:Tricks]]
[2] => [[Category:Google Search]]
[3] => [[Category:Filters]]
[4] => [[Category:Search]]
[5] => [[Category:Tips]]
)
[1] => Array
(
[0] => Category
[1] => Category
[2] => Category
[3] => Category
[4] => Category
[5] => Category
)
[2] => Array
(
[0] => Google
[1] => Tricks
[2] => Google Search
[3] => Filters
[4] => Search
[5] => Tips
)
)
我正在循环从 wiki 标记文本中检索类别值,无法使用 php
中的正则表达式匹配从标记中获取类别值标记文本包含的类别值为
$input_wiki_markup = "
[[Category:Google]]
[[Category:Tricks]]
[[Category:Google Search]]
[[Category:Filters]]
[[Category:Search]]
[[Category:Tips]]";
这是我目前尝试过的方法
$matches = array();
if(preg_match("/\[\[(Category):(.+)*\]\]/i", $input_wiki_markup, $matches)){
print_r($matches);
}
这是输出
Array
(
[0] => [[Category:Google]][[Category:Tricks]][[Category:Google Search]][[Category:Filters]][[Category:Search]][[Category:Tips]]
[1] => Category
[2] => Google]][[Category:Tricks]][[Category:Google Search]][[Category:Filters]][[Category:Search]][[Category:Tips
)
但我正在尝试获取仅包含冒号后类别值的输出数组,即
Array
(
[0] => Google
[1] => Tricks
[2] => Google Searcg
)
以此类推
我应该对我的正则表达式进行哪些更改以仅获取 $mathces 数组中填充的类别值 或者我应该使用其他 php 函数而不是 preg_match 吗?
请注意,$input_wiki_markup
还包含 [[Categpry:xyz]]
标签周围的其他文本
你只需要 全部
$input_wiki_markup="
[[Category:Google]]
[[Category:Tricks]]
[[Category:Google Search]]
[[Category:Filters]]
[[Category:Search]]
[[Category:Tips]]
";
$matches = array();
if(preg_match_all("/\[\[(Category):(.+)*\]\]/i", $input_wiki_markup, $matches)){
print_r($matches);
}
输出:
Array
(
[0] => Array
(
[0] => [[Category:Google]]
[1] => [[Category:Tricks]]
[2] => [[Category:Google Search]]
[3] => [[Category:Filters]]
[4] => [[Category:Search]]
[5] => [[Category:Tips]]
)
[1] => Array
(
[0] => Category
[1] => Category
[2] => Category
[3] => Category
[4] => Category
[5] => Category
)
[2] => Array
(
[0] => Google
[1] => Tricks
[2] => Google Search
[3] => Filters
[4] => Search
[5] => Tips
)
)