473,388 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Storing result in file with delimiter

123 100+
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.  
Jul 15 '08 #1
2 1403
code green
1,726 Expert 1GB
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]
Jul 16 '08 #2
ajd335
123 100+
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..
Jul 16 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: nospam | last post by:
If I had a text file with the following two columns: key1 value1 key2 value2 key3 value3 How would I read in this file and create an associative array?
2
by: Dave Stone | last post by:
Does anyone know if it's possible to use the wizard or DTS Designer to accept a source file with the following simplified format: <field1label>: <record1field1value> <field2label>: ...
7
by: Arnold | last post by:
I need to read a binary file and store it into a buffer in memory (system has large amount of RAM, 2GB+) then pass it to a function. The function accepts input as 32 bit unsigned longs (DWORD). I...
2
by: Mark Hannon | last post by:
I am trying to wrap my brain around storing form elements inside variables & arrays before I move on to a more complicated project. I created this simple example to experiment and as far as I can...
11
by: bissatch | last post by:
Hi, I am trying to upload an image, create a new file based on that image and then store the base64 encoded image data in a database. I dont really know where my code is going wrong so I will...
11
by: Skc | last post by:
I have a .txt which has been exported as a .csv from an external source. What i need to do is to import this into SQL2000 (into a table) but I need to do special things on the data: 1. I need to...
8
by: asrs63 | last post by:
Hi, I am a newbee and have a comma seperated flat-file and a DTD. I need to write a C# program which will read the text file and convert it to a XML file as per the the definition in the DTD. I...
19
by: Lee Crabtree | last post by:
Is there a class in the framework that allows me read text from a file in an unbuffered manner? That is, I'd like to be able to read lines in the same manner as StreamReader.ReadLine(), but I also...
4
by: MikeJ | last post by:
make a While loop ofs = TextFileServer("somefile") string srow while (ofs=false) { srow=ofs.getRow(); Console.Writeline(srow); }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.