473,387 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

preg_match(_all) & big strings

I have problem with large textfiles! When I load over 4MB xml and then
try to preg_match something in this I get always FALSE!
I have <File>....</File> tags in XML. Between tags is files contents
BASE64 encoded! When xml contains only one big over 4MB file in it,
preg_match and preg_match_all doesnt find it! When included file size is
nelow 4MB, preg functions works perfectly!
But PHP manual says that there is no size limitations to strings?!?!

Is this somekind BUG or why doesnt preg work over 4MB matches??? Looks
like problem is when patern-matched string is over 4MB, not the string
where to search!?!?!

How to get work this function? I have portal what should work with large
XML files (contains one ore more BASE64 coded files with unlimited
sizes). How can I get contents of those tags from XML???

/Sorry my bad english, my native language is estonian/

/Muumac
Jul 17 '05 #1
2 8469
"Muumac" wrote:
I have problem with large textfiles! When I load over 4MB xml and then
try to preg_match something in this I get always FALSE!
I have <File>....</File> tags in XML. Between tags is
files contents
BASE64 encoded! When xml contains only one big over 4MB file in it, preg_match and preg_match_all doesnt find it! When included file size is
nelow 4MB, preg functions works perfectly!
But PHP manual says that there is no size limitations to strings?!?!
Is this somekind BUG or why doesnt preg work over 4MB matches??? Looks
like problem is when patern-matched string is over 4MB, not the string
where to search!?!?!

How to get work this function? I have portal what should work with
large
XML files (contains one ore more BASE64 coded files with unlimited sizes). How can I get contents of those tags from XML???

/Sorry my bad english, my native language is estonian/

/Muumac


If all else fails, why don’t you try ereg functions. I think preg
and ereg are written by different developers, so they probably have
different limitations.

If that fails, the other option is to read the file and parse it into
an array, and do a regex by looping thru the array.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-preg_mat...ict145502.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=487022
Jul 17 '05 #2
On Wed, 01 Sep 2004 20:25:03 +0300, Muumac <ma*****@hot.ee> wrote:
I have problem with large textfiles! When I load over 4MB xml and then
try to preg_match something in this I get always FALSE!
I have <File>....</File> tags in XML. Between tags is files contents
BASE64 encoded! When xml contains only one big over 4MB file in it,
preg_match and preg_match_all doesnt find it!
First question is why are you trying to parse XML with regular expressions,
instead of an XML parser? You can't create a single regular expression capable
of parsing arbitrary XML as they aren't capable of maintaining enough state
information. They'll work for simple cases, but isn't that defeating part of
the purpose of XML?

http://www.php.net/manual/en/ref.xml.php uses Expat, which streams through the
XML file in manageable chunks, and may be more appropriate for your usage. I
think you'd just set up a handler and watch for <File> elements, and set up a
character data handler for the contents.
When included file size is
nelow 4MB, preg functions works perfectly!
But PHP manual says that there is no size limitations to strings?!?!
Well, given that preg_replace is part of the PCRE library, it might be worth
looking directly in the PCRE docs, which say:

<http://www.pcre.org/pcre.txt>

The maximum length of a subject string is the largest posi-
tive number that an integer variable can hold. However, PCRE
uses recursion to handle subpatterns and indefinite repeti-
tion. This means that the available stack space may limit
the size of a subject string that can be processed by cer-
tain patterns.

OK, so that appears to say for very simple expressions that you can probably
handle about 2GB of data, but that goes down depending on how complex your
expression is - possibly going down a lot, since it's based on "stack space",
if it's referring to the normal stack space that the OS provides processes.
What pattern are you using?
Is this somekind BUG or why doesnt preg work over 4MB matches??? Looks
like problem is when patern-matched string is over 4MB, not the string
where to search!?!?!
Hang on - I think I'm reading that incorrectly, but are you saying you're
supplying a 4MB _pattern_? A pattern that large is pretty absurd, and then
there's this from the docs:

The maximum length of a compiled pattern is 65539 (sic)
bytes if PCRE is compiled with the default internal linkage
size of 2. If you want to process regular expressions that
are truly enormous, you can compile PCRE with an internal
linkage size of 3 or 4 (see the README file in the source
distribution and the pcrebuild documentation for details).
If these cases the limit is substantially larger. However,
the speed of execution will be slower.
How to get work this function? I have portal what should work with large
XML files (contains one ore more BASE64 coded files with unlimited
sizes). How can I get contents of those tags from XML???


Another point to look out for is PHP's memory_limit directive - if you're
loading the whole lot into memory and processing it you're likely to hit that
limit. That's probably another point where the XML parser functions above will
win out, as you can read it in bits and write it off into a file rather than
having the whole lot in memory at one time.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Han | last post by:
I'm wondering if someone can explain why the following works with preg_match_all, but not preg_match: $html = "product=3456789&amp;" preg_match_all ("|product=(\d{5,10})&amp;|i", $html, $out); $out...
1
by: Daniel | last post by:
I've been searching the net and Google news groups for a preg_match expression that will return true on strings containing (uppercase and lowercase) characters of A-Z, 0-9 and for instance Swedish...
2
by: pomho | last post by:
Hi all, Even having read the PHP Manual, I can't understand the difference between the ereg function and the preg_match... Could anyone help ? thx in advance, --
22
by: stoppal | last post by:
need to extract all text between the following strings, but not include the strings. "<!-- #BeginEditable "Title name" -->" "<p align="center">#### </p>" I am using preg_match(????, $s,...
4
by: siromega | last post by:
I have a string I'd like to have broken into parts using preg_match. I used a regular expression from the Perl FAQ (http://perlfaq.cpan.org/): push(@new, $+) while $text =~ m{ "(*(?:\\.*)*)",?...
4
by: Yandos | last post by:
Hi all, I'd like to work with a binary file.... I read the whole file into variable (it conatains binary data from 00-FF): $fp=fopen($cfg,"r"); $content=fread($fp,filesize($cfg));...
3
by: Sam Waller | last post by:
I need a regular expression for preg_match to find all of the strings between '>' and '<' from html. Eg. 1. <TD><FONT SIZE='2'>XXX</FONT></TD> 2. <TD><FONT SIZE='2'><A...
2
by: jonathan184 | last post by:
Hi I am trying to use if statements to search strings on each line and if it finds matches to the string write to a variable and then echo variable and the loop starts again. The match is being...
13
by: chadsspameateremail | last post by:
I might have found a problem with how preg_match works though I'm not sure. Lets say you have a regular expression that you want to match a string of numbers. You might write the code like this:...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.