我有一些数组,我想删除具有特定字符串的数组。 代码我已经尝试了
<?php
if(isset($_POST['hapuskan'])){
$fileset=$_POST['kiwet'];
$fileset = explode("\n", $fileset);
$cari = $_POST['hapus'];
$input = preg_quote($cari, '~');
$result = preg_grep('~' . $input . '~', $fileset);
$tampil = array_diff($fileset, $result);
$handle = fopen ("file.txt", "w");
foreach ($tampil as $key) {
if($key!==""){
$key = $key."\n";
fputs($handle, $key);}}}
header('location:index.php');
?>
file.txt中我的数组样本是:
bandung
band
beattle band
bandung indonesia
indonesia
我想删除&#34;乐队&#34;和#34; beattle乐队&#34;只有,但我的代码&#34; bandung&#34;,&#34; band&#34;和&#34; bandung indonesia&#34;也会删除。怎么解决这个问题?