English 中文(简体)
查阅使用php的文本档案?
原标题:accessing text files using php?

i 想知道,如何利用实验室获取文本档案,并使用“基地”系统阵列显示信息,这似乎是一个新问题,但一味处理外部档案。

这里就是这样。

家庭:

ha15rs,250,home2.gif,2
ha36gs,150,home3.gif,1
ha27se,300,home4.gif,4
ha4678,200,home5.gif,5

我想要做的是,把这一信息放在一个html的桌上,每条线是一行,4英勇代表数据! 感谢老板:

最佳回答

a 开始处理这一问题:

  # echo before table headline
    ...........
    $handle = @fopen("myfile.txt","r");
    # read line by line
    while (($buffer = fgets($handle, 4096)) !== false) {
        echo  <tr> ;
            $array = explode( , , $buffer);
        foreach($array as $val){
             echo  <td> .$val. </td> ;      
            } 
        echo  </tr> ;       
    }
问题回答

类似ma马分离的价值观。 见

你们可以做这样的事情:

<?php
$file = file_get_content( file.txt );

$array = explode("
", $file);

http://en.wikipedia.org/wiki/Newline”rel=“nofollow”

通常:

  • Gnu/Linux / Unix / MacOS since X use " "
  • Windows use " "
  • MacOS before X use " "

you should look at the file() function too, it reads the file into an array line by line.
after that you can seperate the values with explode().

<?php
  $foo = file( example.txt );
  // will echo the 2nd line of the example.txt-file
  echo $foo[1];
  // echos all items seperated by a comma
  foreach($foo as $line=>$values){
    $value_arr = explode( , ,$values);
    echo  line # .$line. :  ;
    foreach($value_arr as $id=>$item){
      echo $id. :  .$item. ;  ;
    }
    echo "
";
  }
?>




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签