rename the file


Posted on 16th Feb 2014 07:03 pm by admin

File.txt

Code: ***DOCUMENT***
..DN:
000044255
..CB:
..SN:
..PY:
2009
..ED:
LA
..ED:
Home
..ID:
***DOCUMENT***
..DN:
000044254
..CB:
..SN:
..PY:
2009
..ED:
LA
..ED:
Edition
..PT:
ID:

Code: <?php
$file = fopen($argv[1], "r") or exit("Unable to open file!");
$i=1000;
while(!feof($file)){
while(!feof($file))
{
$line=fgets($file);
if(strstr($line,"***DOCUMENT")){

$file1 = fopen($argv[1].$i.".txt",'w') or exit("Unable to open file!");
}
fwrite($file1,$line);
if(strstr($line,'..ID:')){
fclose($file1);
break;
}
}
$i++;
}
fclose($file);
?>


Hi,

This is the above file. I have splitted this file naming starting with 1000.txt.....
How to name taking the value of ED.
I have to name it as 1000.Home.txt
1001.Edition.txt

No comments posted yet

Your Answer:

Login to answer
78 Like 48 Dislike
Previous forums Next forums
Other forums

preg_replace question
Hello!!

I hope someone can help me with preg_replace.

I load two tables from an extern

include problem
I have my root folder as:
Code: $root = $_SERVER["SITE_HTMLROOT"]; // the server root<

PHP, Arrays & A Lot Of Confusion
I've been doing basic PHP work on sites for a few years now, but I've never been tempted to learn ho

how to remove in php string display
My code is $message="We're looking at developing our website."; $body= "My mess

mr8m - reverse document
Friends,

I'm trying to reverse a document held by MIRO, but it reports the message balan

Why does my crawler script suddenly end with no error?
Hi.

I have written a web crawler script. It will visit a large number of URL's with cURL.

Add trigger to UpdatePanel programmatically
Hi,I'm working on a website which uses AJAX and Masterpages. What I have is an AJAX UpdatePanel whi

Help with Contact Form
I have this Form on an html page and the associated code on page.php (below).
I keep getting the

[newb] Image hosting help.
Hey there, I'm new to php, I know some basics and i can code PWN, I'm only 14 but I'm interested in

How to create a static html menu from a database
Hi,

I have built a small cms which allows me to create simple html pages and then upload them

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash