Forum Moderators: coopster

Message Too Old, No Replies

preg_replace limit?

         

DrDoc

1:01 am on Mar 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there a limit to how much data preg_replace can handle?

Say that I have a 20k string, can I just do a preg_replace to replace all newlines with <br>?

aaronc

1:27 am on Mar 20, 2003 (gmt 0)

10+ Year Member



Wow, a 20k string is big. I don't know if php will even support a 20k variable.
I'm assuming you're getting it from a file.
It might make more sense to read in the file a line at a time and do each line and output it back to another file.

andreasfriedrich

1:36 am on Mar 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The longer the string the longer will the re engine need to do the matching. If you use backreferences the time will increase exponentially. That being said 20K is not a problem at all.

I just run a preg_replace [php.net] on a 213K file. Processing was still very fast. If you get really large strings from a file it might indeed be better to run the re on chunks of the file.

nl2br [php.net] might be helpful as well.

Andreas

DrDoc

5:01 am on Mar 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's what I thought as well... that there really isn't a limit. The other thing is that I'm not just doing the \n=>br replace. I need to be able to match and/or replace text strings spread out over the whole file. Line-by-line matching isn't an option.

And yes, it's input from a file... Size anywhere between a few Kb up to almost 50...

It's working again now .. Don't know why it didn't for a while. :)

nosanity

6:26 am on Mar 20, 2003 (gmt 0)

10+ Year Member



Just to make people scratch their heads, I just tried a preg_replace on a 50 MB file. Well, it worked, but it made my patheticly slow dev server crawl, but it has tons of ram...

noSanity