function words_cb($ar)
{   
     foreach ($ar as $tmp)
{         echo $tmp . ' ';
}
}
在一PHP文件中调用上面的函数,就可输出 一串连接的字符,现我不输出,

1 要把此串字符写到 一个名为split_word.txt文件中去 (写入时 先把split_word.txt 中的内容删除)
2 在下面的函数中怎么读取 上面存的 split_word.txt 中的内容呀,
 function read($file) 
{   
   ...
   return $file;
}
thanks

解决方案 »

  1.   

    file_put_contents,默认就是覆盖。
      

  2.   

    function read($file){
        $handle = fopen($file,"r");
        $contents = fread($handle, filesize ($file));
        fclose($handle);
        return $contents;
    }楼主要多看手册
      

  3.   

    function read($file)  
    {  
      $fp=fopen(.. ,'r');
      if(!$fp)echo .. exit;
      while(!feof($fp))
     {
      $line=fgets($fp,999); 
      echo $line.'<br>';
     }
    fcolse($fp);
      ... 
      return $file; 

    不知道对不对,随手写的
      

  4.   

    function words_cb($ar, $file)

       $str = '';
        foreach ($ar as $tmp)
       {        $str .= $tmp . ' ';
        }
       file_put_contents($file, $str);
    }function read($file) 

      return file_get_contents($file);

    前提是文件夾及其文件有讀寫權限
      

  5.   

    谢谢。
    我最近用了
    $str .= $tmp . ' ';
    把$str传出来,弄好了