如何使用php获取文本文件中的特定字符串

如何使用php获取文本文件中的特定字符串,php,Php,我想回显/获取文本中的特定字符串,如: 该文件是test.txt 文件内容字符串为“data.I.d.1.in” 如何仅回显/获取no'1'或'I'd'其他字符串。。。 请帮帮我试试这个 <?php $data = file_get_contents("input.txt"); //read the file $convert = explode("\n", $data); //create array separate by new line for ($i=0;$i<count

我想回显/获取文本中的特定字符串,如: 该文件是test.txt 文件内容字符串为“data.I.d.1.in” 如何仅回显/获取no'1'或'I'd'其他字符串。。。 请帮帮我试试这个

<?php
$data = file_get_contents("input.txt"); //read the file
$convert = explode("\n", $data); //create array separate by new line

for ($i=0;$i<count($convert);$i++)  
{
echo $convert[$i].', '; //write value by index
}
?>


输出:

数据,我想,1,in, 或者如果它是针对某个字符串的

<?php
$data = file_get_contents("input.txt"); //read the file
$convert = explode("\n", $data); //create array separate by new line

for ($i=0;$i<count($convert);$i++)  
{
echo $convert[$i]=='1'. ; //write value by index
}
?>


输出:


1
到目前为止你都尝试了什么?我只使用fopen,但我不知道如何获取某些数据,请你举个例子……我仍然不了解phpTq jned,我会尝试这个……tq soo muchok user3821200。欢迎:)Tq Alex我将尝试Tq Soo muchNo问题。如果你有麻烦请告诉我你救了我,我有问题如何将$V3FTD字符串改成其他字符串你能给我举个例子吗抱歉问了这么多问题…我还是noob@user3821200嗨,我很高兴这有帮助。请向上投票给我的答案,然后单击问题旁边向下箭头下方的勾号,将其选为最佳答案。然后用更具体的细节提出一个新问题,我将尝试回答它。谢谢codeslayer我会试试这个,tq-soo非常感谢你的帮助
<?php

$file= file_get_contents("test.txt"); 
$convert = explode("\n", $file); `

for ($i=0;$i<count($convert);$i++)  
{

    if($i<count-1)///make your you doesn't have , in your last line
    {

        echo $convert[$i].', '; //it is writing the value`
    }
    else
    {

        echo $convert[$i];`

    }

}
?>
$string = " data . I'd . 1 .in ";
// remove the spaces
$string = str_replace(' ', '',$string);
// convert to array
$words = explode('.', $string);

print $words[1]; // I'd
print $words[2]; // 1