Re: \nhelp
| From: | Jason Stechschulte | Date: | Fri, 18 May 2001 12:37:14 +0000 |
| Subject: | Re: \nhelp | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-53398@lists.php.net to get a copy of this message | ||
On Wed, May 16, 2001 at 05:13:16PM -0400, jtjohnston wrote:
> I am parsing the contents of a text file.
Congratualtions.
> I have certain lines that start with "&&4;" I would like to attach these
> lines to the previous line as follows. But I don't know how. I figure I
> have to search and replace for "\n&&4;" but ... ?
You could try something like this:
<?php
$file = file("file");
for($i = 0, $k = 0; $i < sizeof($file); $i++) {
if(substr($file[$i], 0, 4) == "&&4;") {
$newfile[$k - 1] .= $file[$i];
}
else {
$newfile[$k++] = $file[$i];
}
}
?>
--
Jason Stechschulte
jpstech@unoh.edu
--
Perl programming is an *empirical* science!
-- Larry Wall in <10226@jpl-devvax.JPL.NASA.GOV>