On Sun, 2002-02-03 at 21:34, Martin Towell wrote:
> is that a direct copy from your code? - if it is, there's two errors
> 1. you have a comma just before the closing backet
> 2. the function is : implode(string glue, array pieces)
> so that would be : $content = implode("\n", $lines);
> ie. the two arguments are the wrong way around
> Martin
Actually, implode() will take its arguments in either order, so
there's really only one thing (the comma) which could be causing
the problem.
Also, for the original poster: if you only need to do simple
string replacements, you should see whether str_replace() will
serve your purpose. It's much less expensive than ereg_replace().
If you feel that you require regular expressions, the preg_*()
functions are less expensive than the ereg_*() equivalents.
Torben
> -----Original Message-----
> From: John P. Donaldson [mailto:[EMAIL PROTECTED]]
> Sent: Monday, February 04, 2002 4:32 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] ereg_replace help
>
>
> I'm not actually replacing \n with <br>, I just used
> that as an example. When I tried Martin's solution, I
> got a parse error on this line:
>
> $content = implode($lines, "\n",);
>
> I checked the manual and it's constructed properly ..
> I think. What could be giving me the parse error on
> this line. The previous line reads:
>
> $lines = file("log.txt");
>
> Thanks,
> John
>
>
>
>
> --- Mike Frazer <[EMAIL PROTECTED]> wrote:
> > nl2br() would serve that purpose as well. See the
> > Strings section of the
> > Functions Reference in the manual.
> >
> > Mike Frazer
> >
> >
> >
> > "Martin Towell" <[EMAIL PROTECTED]> wrote in
> > message
> >
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > > $lines = file("filename_here.blah"); // read in
> > file as an array
> > > $content = implode("\n", $lines); // join it
> > all back together
> > > $new_cont = ereg_replace("from", "to", $content);
> > > fopen(...); fputs(..., $new_content);
> > fclose(...);
> > >
> > >
> > > if your intent is to replace all new lines with
> > <br>'s then use this
> > instead
> > > ...
> > >
> > > $lines = file("filename_here.blah"); // read in
> > file as an array
> > > $content = implode("<br>", $lines); // join it
> > all back together
> > > fopen(...); fputs(..., $content); fclose(...);
> > >
> > >
> > > hope this helps
> > >
> > > -----Original Message-----
> > > From: John P. Donaldson
> > [mailto:[EMAIL PROTECTED]]
> > > Sent: Monday, February 04, 2002 3:39 PM
> > > To: php
> > > Subject: [PHP] ereg_replace help
> > >
> > >
> > > I have a file open and can successfully write to
> > it,
> > > but I was to be able to search for a certain
> > string of
> > > text and replace it with a string of text. I
> > can't
> > > figure out how to construct a proper ereg_replace
> > > statement to search through this file and do the
> > > replacing. Examples I've seen are in the manner
> > of:
> > >
> > > $text = "line1\nline2\n";
> > > fputs(ereg_replace("\n", "<br>", $text));
> > >
> > > But how do I set the value of $text to be the
> > entire
> > > contents of the text file I've got open so it can
> > > search through the entire file to find matches and
> > > replace those matches? Any help is greatly
> > > appreciated.
> > >
> > > Thanks,
> > > John
> > >
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Great stuff seeking new owners in Yahoo! Auctions!
> > > http://auctions.yahoo.com
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit:
> > http://www.php.net/unsub.php
> > >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Great stuff seeking new owners in Yahoo! Auctions!
> http://auctions.yahoo.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
Torben Wilson <[EMAIL PROTECTED]>
http://www.thebuttlesschaps.com
http://www.hybrid17.com
http://www.inflatableeye.com
+1.604.709.0506
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php