我想在文本中回显/获取某些字符串,如: 该文件是test.txt 文件内容字符串是"数据。我' d。 1。在" 如何回显/只获取没有' 1'或者'我' d'不是其他字符串...... 请帮帮我
答案 0 :(得分:1)
试试这个..
<?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
}
?>
输出:
或者如果它是某个字符串..
<?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 :(得分:0)
<?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];`
}
}
?>
答案 2 :(得分:0)
$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