这是我在文本文件中搜索特定的行代码。现在我想删除和更新结果的比赛之后出现的特定行。但我不是现在该怎么做这个事情。请帮我解决这个问题!
<form action="dis.php" method="post">
<label>Name:</label>
<input type="text" name="search">
<input type="submit" name="send" value="Search">
</form>
<?php
if (isset($_POST['send'])) {
$search_txt = $_POST['search'];
$search = $search_txt;
$lines = file('file.txt');
// Store true when the text is found
$found = false;
foreach($lines as $line)
{
if(strpos($line, $search) !== false)
{
$found = true;
echo '<h1>The Folowing Contacts Exists against your search:</h1><br> '.$line."<br>";
}
}
// If the text was not found, show a message
if(!$found)
{
echo 'No match found';
}
}
你能简单地把一个变量来计算文件中的行,然后插入根据是什么?
$found = false;
$currentRow=0;
foreach($lines as $line)
{
$currentRow++;
if(strpos($line, $search) !== false)
{
$found = true;
echo '<h1>The Folowing Contacts Exists against your search:</h1><br> '.$line."
<br>";
}
}
$lines[$currentRow] = 'my modified line';