Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP标签系统_Php_Tagging - Fatal编程技术网

PHP标签系统

PHP标签系统,php,tagging,Php,Tagging,我有这个剧本: <?php $string = "@Erol Simsir @Hakan Simsir"; $output = preg_replace("/@([^\s]+)/", "<a href=\"?tag=$1\">$1</a>", $string); echo $output; ?> $string = $_POST["tags"]; $output = preg_replace("/#([^\s]+)/", "&l

我有这个剧本:

<?php

    $string = "@Erol Simsir @Hakan Simsir";
    $output = preg_replace("/@([^\s]+)/", "<a href=\"?tag=$1\">$1</a>", $string);
    echo $output;

?>
$string  = $_POST["tags"];
$output = preg_replace("/#([^\s]+)/", "<a href=\"?tag=$1\">$1</a>", $string);
$finalOutput = explode(" ", $output);
$count = count($finalOutput);
$i = 0;
while($i < $count) {
    echo $finalOutput[$i] . "<br />";
    $i = $i + 1;
}

此脚本检测前面带有“@”符号的所有单词,并将其更改为链接/标记。然而,我不想要一个标签系统,而是一个标签系统,就像在Twitter上一样,在那里你可以做“@JohnDoe”,用户JohnDoe就是推特发到的人

因此,我需要将所有标记存储在一个数组中的字符串中,以便在以后的SQL查询中使用它们

我怎样才能做到这一点

更新

我现在有这个代码:

$string  = $_POST["tags"];
$output = preg_replace("/@([^\s]+)/", "<a href=\"?tag=$1\">$1</a>", $string);
$finalOutput = explode(" ", $string);
$count = count($finalOutput);
$i = 0;
while($i < $count) {
echo $finalOutput[$i];
$i = $i + 1;
}
$string=$\u POST[“tags”];
$output=preg_replace(“/@([^\s]+)/”,“”,$string);
$finalOutput=explode(“,$string);
$count=计数($finalOutput);
$i=0;
而($i<$count){
echo$finalOutput[$i];
$i=$i+1;
}
问题是,输出中的标记看起来像这样:@john@sandra等。如何删除输出中的@符号

$array = explode(' ', $string);
请尝试以下代码:)

$count=count($array);
$tag_array=array();
$j=0;
对于($i=0;$i而言,最简单的方法是使用:


我发现这个脚本有点问题:

<?php

    $string = "@Erol Simsir @Hakan Simsir";
    $output = preg_replace("/@([^\s]+)/", "<a href=\"?tag=$1\">$1</a>", $string);
    echo $output;

?>
$string  = $_POST["tags"];
$output = preg_replace("/#([^\s]+)/", "<a href=\"?tag=$1\">$1</a>", $string);
$finalOutput = explode(" ", $output);
$count = count($finalOutput);
$i = 0;
while($i < $count) {
    echo $finalOutput[$i] . "<br />";
    $i = $i + 1;
}
$string=$\u POST[“tags”];
$output=preg#u replace(“/#([^\s]+)/”,“”,$string);
$finalOutput=explode(“,$output”);
$count=计数($finalOutput);
$i=0;
而($i<$count){
echo$finalOutput[$i]。“
”; $i=$i+1; }

它还会分解所有不带@符号的单词。当我在表单中插入“JohnDoe”时,它也会接受,但它应该只接受带有@符号的文本。因此,当我在脚本中插入“JohnDoe”时,它应该验证并说这不是有效的标记。只有当输入像“@john@steve”等时,它才会工作。

preg\u match
分解
插入