我在爆炸线上得到一个解析错误。 我只想把我已经存储在我的数据库中的关键字(brad pitt,fight club,project mayhem)转换成用逗号分解的阵列。然后将该数组与新用户输入合并。
<?php
$tags = $_POST['tagArray'];
$title = $_POST['title'];
$DBServer = "localhost";
$DBUser = "------";
$DBPass = "-------";
$DBName = "movies";
$conn = mysqli_connect($DBServer, $DBUser, $DBPass, $DBName);
$query = "SELECT keywords FROM movieTitles WHERE movie='" .$title. "'";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_array($result);
$keywords = $row['keywords'];
$current = explode("," $keywords[0]);
$array = array_unique(array_merge($tags,$current));
echo $array;
mysqli_close($conn);
?>
答案 0 :(得分:1)
$current = explode(",", $keywords[0]);
你错过了一个额外的逗号
答案 1 :(得分:0)
您错过了分隔符和文本之间的逗号
$current = explode("," , $keywords[0]);
答案 2 :(得分:0)
$current = explode("," $keywords[0]);
您错过了逗号,以分隔函数参数
应该是:
$current = explode(",", $keywords[0]);
但除了您的错误,$row['keywords'];
是一个字符串,因此使用[0];
将搜索字符串的第一个字符。例如:
$row['keywords'] = "Test";
echo $row['keywords'][0]; // Output T
总的来说,这样做最好:
$current = explode(",", $keywords);