Php 以字符串作为分隔符的Echo数组

Php 以字符串作为分隔符的Echo数组,php,arrays,Php,Arrays,我在PHP中有以下代码,它在文件中搜索包含字符串的行: <?php echo "Results for: "; echo ($_POST['query']); echo "<br><br>"; $file = 'completed.db'; $searchfor = ($_POST['query']); header('Content-Type: text/plain'); $contents = file_get_contents($file); $pattern

我在PHP中有以下代码,它在文件中搜索包含字符串的行:

<?php
echo "Results for: ";
echo ($_POST['query']);
echo "<br><br>";
$file = 'completed.db';
$searchfor = ($_POST['query']);
header('Content-Type: text/plain');
$contents = file_get_contents($file);
$pattern = preg_quote($searchfor, '/');
$pattern = "/^.*$pattern.*\$/m";
if(preg_match_all($pattern, $contents, $matches)){
   echo "Found matches:\n";
   echo implode("\n", $matches[0]);
}
else{
   echo "No matches found";
}
?>

只需将break标记添加到字符串中

echo implode("\n<br>", $matches[0]);
回波内爆(“\n
”,$matches[0]); 由于内爆只发生在两次爆炸之间,所以还有一次要追踪

echo "<br>";
echo“
”;
下面的代码只是将内爆与不同的第一个参数一起使用,bu还将分隔符添加到末尾(根据规范)

$entry='
'; echo内爆($entry,$matches[0])。$entry;
内爆(“
,$matches[0]);你能解释一下你的答案是如何解决问题的吗?只有代码的答案不是很有用,特别是对于那些偶然发现这篇文章的读者来说。谢谢!
echo "<br>";
$entry = '<br>';
echo implode($entry, $matches[0]).$entry;