我在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";
}
?>
在線,echo implode("\n", $matches[0]);
在回聲的陣列,用空格分開。如果我想用不同的字符串分隔項目,比如說$entry = '<br>'
,那麼你會怎麼做?
例如,如果$matches
是
- 一個
然後,命令應呼應:
one<br>two<br>three<br>
破滅( 「
」,$比賽[0]) ; – Brett
[如何在php數組中使用echo來返回字符串]可能的重複(http://stackoverflow.com/questions/10051451/how-to-use-echo-in-php-array-to-return-as -a-string) – miken32