在处理标签过程中我遇到了一个问题。这里我使用preg_match_all方法来选择特定标签。
使用后,我得到这样的数据。这里发布php代码和输出请检查。
<?php
$comment = $_POST['comment'];
preg_match_all("/(@\w+)/", $comment, $matches);
echo "<pre>"; print_r($matches);
?>
输出:
<pre>Array
(
[0] => Array
(
[0] => @name
[1] => @variables
)
[1] => Array
(
[0] => @name
[1] => @variables
)
)
这里我怀疑如何用逗号分隔转换这个数组。
期待:
$ tagging =(@ name,@ variables);
任何人都知道请帮我解决这个问题。
答案 0 :(得分:0)
$tagging = implode (",", $matches[1]); // '@name,@variables'
答案 1 :(得分:0)
试试这个:
<?php
$comment = $_POST['comment'];
preg_match_all("/(@\w+)/", $comment, $matches);
foreach($matches as $val){
echo implode (",", $val);
//echo '(' . implode (",", $val) . ')';
}
?>
如果你想要paranthesis那么取消评论第二行