Connecting Tech Pros Worldwide Forums | Help | Site Map

Storing result in file with delimiter

Member
 
Join Date: Apr 2008
Location: United states
Posts: 123
#1: Jul 15 '08
Hey all
I have written script that can match for certain patter in all the files in directory and the result of each file is stored in $final.Now I am storing the value of $final in one text file...Then I am getting below results..
Expand|Select|Wrap|Line Numbers
  1. (.*)$/',$lines,$matches))10.(.*)$/',$lines,$matches))(.*)$/',$lines,$matches)) wks^M10.192^M06-5B--6A^Mi001^M10.5^M00-5F-68^Min-01^M10.209^M 00-57-A0-F3^M 
  2.  
I want to have all the output using "NEW line" delimiter. how can I do so, Just for understanding I am giving the code from which i store results into one file.In the above result $final contains ( wks^M10.192^M06-5B--6A^M ) - match from file1..and so on..

Expand|Select|Wrap|Line Numbers
  1. $dirname = "/home/ajd/ip";
  2. if($handle = opendir($dirname))
  3. {
  4.     while(false !== ($filename = readdir($handle))){
  5.         if (is_readable($filename)) {
  6.   if ($handle1 = fopen($filename, "r") ) {
  7.                 while(!feof($handle1)) {
  8.                     $lines = fgets($handle1);
  9. $ar1[1] = ..............; $ar2[1]=......;$ar3[1]=......;
  10. $final = $ar1[1].$ar2[1].$ar3[1];
  11. $path = "/home/ajd/ip/result.txt";  
  12. $fp = fopen($path,'a') or die('cant open');
  13. fwrite($fp,$final);
  14. fclose($fp);
  15. fclose($fp); } } } 
  16. closedir($handle); } ?>
  17.  
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,079
#2: Jul 16 '08

re: Storing result in file with delimiter


I think you are asking how to put line breaks in your file.
This varies on your operating system
but you need to concatenate the relevant ASCII characters in your code
Expand|Select|Wrap|Line Numbers
  1. Microsoft Windows    "\r\n"
  2. Apple Macintosh       "\r"
  3. Linux and later MAC  "\n"
ie [PHP]$final = $ar1[1]."\r\n".$ar2[1]."\r\n".$ar3[1];[/PHP]
Member
 
Join Date: Apr 2008
Location: United states
Posts: 123
#3: Jul 16 '08

re: Storing result in file with delimiter


Quote:

Originally Posted by code green

I think you are asking how to put line breaks in your file.
This varies on your operating system
but you need to concatenate the relevant ASCII characters in your code

Expand|Select|Wrap|Line Numbers
  1. Microsoft Windows    "\r\n"
  2. Apple Macintosh       "\r"
  3. Linux and later MAC  "\n"
ie [PHP]$final = $ar1[1]."\r\n".$ar2[1]."\r\n".$ar3[1];[/PHP]

Thanks for your help Code Green..
Reply


Similar PHP bytes