473,799 Members | 2,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8558
"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.andyhsoftwa re.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
4697
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 = 3456789 preg_match ("|product=(\d{5,10})&amp;|i", $html, $out);
1
5404
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 characters Å Ä Ö. It should return false on strings containing stuff like -#¤%\"()=?&/. The thing is, I don't want to specifically allow Å Ä Ö, I want a more general rule in case other characters like ü or ø turn up. Is this possible to do? ...
2
4461
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
2776
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, $results)
4
1832
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{ "(*(?:\\.*)*)",? # groups the phrase inside the quotes | (+),? | , }gx;
4
11631
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)); fclose($fp);
3
3025
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 HREF=http://www.whatever.com/...7>ZZZ</A></FONT></TD> 3. <TD ALIGN=CENTER><FONT SIZE='2'>Y/Y</FONT></TD> #1 matches should be "", "XXX", and "" #2 should be "", "", "ZZZ", "", "" #3 should be "", "Y/Y", ""
2
1576
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 found fine but anything under the matched record is getting the same value of the variable when there is no match. I tried if and elseif and i get the same problem this is the code i am using in the loop. Could somebody help me please. ...
13
5374
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: preg_match( '/^+$/', $TestString ); OK everything seems fine. However, did you know if you pass the following to preg_match: "12345\n" it will return that a match occurred?!? Even though the newline is not a valid character in our regular...
0
9686
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10475
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10250
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10026
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.