PHP拆分和替换
我有这个密码:PHP拆分和替换,php,replace,split,Php,Replace,Split,我有这个密码: $username = $_GET['us']; 以及: 但也可以是: $k1 = $_GET['set,vip;give,212']; 或 我想看看是哪一个,然后得到这个: $ko1 = 'set vip' 或: 或: 要最终做到这一点: $komenda1 = $ko3.' '.$username; $komenda2 = $ko3.' '.$username; $komenda3 = $ko3.' '.$username; 这是我的代码: <?PHP $use
$username = $_GET['us'];
以及:
但也可以是:
$k1 = $_GET['set,vip;give,212'];
或
我想看看是哪一个,然后得到这个:
$ko1 = 'set vip'
或:
或:
要最终做到这一点:
$komenda1 = $ko3.' '.$username;
$komenda2 = $ko3.' '.$username;
$komenda3 = $ko3.' '.$username;
这是我的代码:
<?PHP
$username = $_GET['us'];
$k1 = $_GET['set,vip;give,212'];
$k1i = $_GET['2'];
$arr2 = explode(";", $k1, $k1i); //podziel na komendy
if ($kli='1'){
$kk11 = arr2[0] //np set,vip
$komenda11 = $str_replace ( ',' , ' ' , $kk11);
}elseif ($kli='2'){
$kk11 = arr2[0]; //np set,vip
$komenda11 = $str_replace ( ',' , ' ' , $kk11);
$kk12 = arr2[1]; //np set,vip
$komenda12 = $str_replace ( ',' , ' ' , $kk12);
}elseif ($kli='3'){
$kk11 = arr2[0]; //np set,vip
$komenda11 = $str_replace ( ',' , ' ' , $kk11);
$kk12 = arr2[1]; //np set,vip
$komenda12 = $str_replace ( ',' , ' ' , $kk12);
$kk13 = arr2[2]; //np set,vip
$komenda13 = $str_replace ( ',' , ' ' , $kk13);
}
$k2 = $_GET['k2']; //pierwsza część komendy np set,vip;give,212
$k2i = $_GET['k2i']; //ilość komend
$arr3 = explode(";", $k1, $k1i); //podziel na komendy
if ($kli='1'){
$kk21 = arr3[0]; //np set,vip
$komenda21 = $str_replace ( ',' , ' ' , $kk21);
$komenda1 = $komenda11.$username.$komenda21;
print($komenda1);
}elseif ($kli='2'){
$kk21 = arr3[0]; //np set,vip
$komenda21 = $str_replace ( ',' , ' ' , $kk21);
$kk22 = arr3[1]; //np set,vip
$komenda22 = $str_replace ( ',' , ' ' , $kk22);
$komenda1 = $komenda11.$username.$komenda21;
$komenda2 = $komenda12.$username.$komenda22;
print($komenda1);
print($komenda2);
}elseif ($kli='3'){
$kk21 = arr3[0]; //np set,vip
$komenda21 = $str_replace ( ',' , ' ' , $kk21);
$kk22 = arr3[1]; //np set,vip
$komenda22 = $str_replace ( ',' , ' ' , $kk22);
$kk23 = arr3[2]; //np set,vip
$komenda23 = $str_replace ( ',' , ' ' , $kk23);
$komenda1 = $komenda11.$username.$komenda21;
$komenda2 = $komenda12.$username.$komenda22;
$komenda3 = $komenda13.$username.$komenda23;
print($komenda1);
print($komenda2);
print($komenda3);
}
?>
您在几行上使用了
arr2
,没有美元符号,因此PHP无法将其识别为变量。将其更改为$arr2
是的,就是这样,但现在我遇到了另一个问题:致命错误:第8行的/home/example.pl/test.php中的函数名必须是字符串,即$komenda11=$str_replace(',','$kkk11)
和它有相同的问题,但相反:函数是str\u replace
,而不是$str\u replace
。
$ko1 = 'set vip'
$ko2 = 'give 212'
$ko1 = 'set vip'
$ko2 = 'give 212'
$ko3 = 'op'
$komenda1 = $ko3.' '.$username;
$komenda2 = $ko3.' '.$username;
$komenda3 = $ko3.' '.$username;
<?PHP
$username = $_GET['us'];
$k1 = $_GET['set,vip;give,212'];
$k1i = $_GET['2'];
$arr2 = explode(";", $k1, $k1i); //podziel na komendy
if ($kli='1'){
$kk11 = arr2[0] //np set,vip
$komenda11 = $str_replace ( ',' , ' ' , $kk11);
}elseif ($kli='2'){
$kk11 = arr2[0]; //np set,vip
$komenda11 = $str_replace ( ',' , ' ' , $kk11);
$kk12 = arr2[1]; //np set,vip
$komenda12 = $str_replace ( ',' , ' ' , $kk12);
}elseif ($kli='3'){
$kk11 = arr2[0]; //np set,vip
$komenda11 = $str_replace ( ',' , ' ' , $kk11);
$kk12 = arr2[1]; //np set,vip
$komenda12 = $str_replace ( ',' , ' ' , $kk12);
$kk13 = arr2[2]; //np set,vip
$komenda13 = $str_replace ( ',' , ' ' , $kk13);
}
$k2 = $_GET['k2']; //pierwsza część komendy np set,vip;give,212
$k2i = $_GET['k2i']; //ilość komend
$arr3 = explode(";", $k1, $k1i); //podziel na komendy
if ($kli='1'){
$kk21 = arr3[0]; //np set,vip
$komenda21 = $str_replace ( ',' , ' ' , $kk21);
$komenda1 = $komenda11.$username.$komenda21;
print($komenda1);
}elseif ($kli='2'){
$kk21 = arr3[0]; //np set,vip
$komenda21 = $str_replace ( ',' , ' ' , $kk21);
$kk22 = arr3[1]; //np set,vip
$komenda22 = $str_replace ( ',' , ' ' , $kk22);
$komenda1 = $komenda11.$username.$komenda21;
$komenda2 = $komenda12.$username.$komenda22;
print($komenda1);
print($komenda2);
}elseif ($kli='3'){
$kk21 = arr3[0]; //np set,vip
$komenda21 = $str_replace ( ',' , ' ' , $kk21);
$kk22 = arr3[1]; //np set,vip
$komenda22 = $str_replace ( ',' , ' ' , $kk22);
$kk23 = arr3[2]; //np set,vip
$komenda23 = $str_replace ( ',' , ' ' , $kk23);
$komenda1 = $komenda11.$username.$komenda21;
$komenda2 = $komenda12.$username.$komenda22;
$komenda3 = $komenda13.$username.$komenda23;
print($komenda1);
print($komenda2);
print($komenda3);
}
?>
Parse error: syntax error, unexpected '[' in /home/example.pl/test.php on line 7