473,585 Members | 2,512 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Storing result in file with delimiter

123 New Member
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 1414
code green
1,726 Recognized Expert Top Contributor
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 New Member
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
11144
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
4360
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>: <record1field2value> - - - - - - - <fieldNlabel>: <record1fieldNvalue> <field1label>: <record2field1value> <field2label>: <record2field2value>
7
728
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 can pass a max of 512 words to it at a time. So I would pass them in chunks of 512 words until the whole file has been processed. I haven't worked...
2
2021
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 tell, it should work but it doesn't. Can someone tell me where I went wrong? <html><head> <title>Form Test</title> <script language="JavaScript>...
11
3239
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 just display it below: The following code contains the script to process the uploaded file, the form to upload the file and then a few links to...
11
3067
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 look for the first three chars and import rows into separate tables. E.g. if the first three chars begin with CCC, then this row goes into the...
8
14575
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 am not able to find anything help-ful and don't know how to begin to code. Can anyone please help me? Thanks in advance
19
5372
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 need to be able to accurately get the position in the file of that line. Since StreamReader and FileStream both buffer data, you can't equate the...
4
2116
by: MikeJ | last post by:
make a While loop ofs = TextFileServer("somefile") string srow while (ofs=false) { srow=ofs.getRow(); Console.Writeline(srow); }
0
8336
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7950
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5389
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3835
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.