473,624 Members | 2,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question about preg_*'s s modifer

Say I have the following script:

<?php
$contents = file_get_conten ts('preg_test.t xt');
echo preg_match("#(. *?)[\r\n]+ddddddddddddd# s",$contents ) ? 'is
equal' : 'is not equal';
?>

Here's preg_test.txt:

http://www.geocities.com/terra1024/preg_test.txt

(it's a malformed part of a postscript file, in case you're curious)

My question is... when I remove the s modifier, preg_match returns
true. When the s modifier is there, it returns false. I'm not really
sure why this is. The s modifier means that . includes new lines and
carriage returns. In either case, it seems like it should match.

Any ideas as to why it doesn't?

Feb 5 '07 #1
7 1402
Rik
yawnmoth <te*******@yaho o.comwrote:
Say I have the following script:

<?php
$contents = file_get_conten ts('preg_test.t xt');
echo preg_match("#(. *?)[\r\n]+ddddddddddddd# s",$contents ) ? 'is
equal' : 'is not equal';
?>

Here's preg_test.txt:

http://www.geocities.com/terra1024/preg_test.txt

(it's a malformed part of a postscript file, in case you're curious)

My question is... when I remove the s modifier, preg_match returns
true. When the s modifier is there, it returns false. I'm not really
sure why this is. The s modifier means that . includes new lines and
carriage returns. In either case, it seems like it should match.
Hmmmz, they both match here in PHP 5.1.4, PCRE Library Version 6.6
06-Feb-2006, with or without the modifier. What version are you using?

--
Rik Wasmus
Feb 5 '07 #2
On Feb 5, 2:13 pm, Rik <luiheidsgoe... @hotmail.comwro te:
yawnmoth<terra1 ...@yahoo.comwr ote:
Say I have the following script:
<?php
$contents = file_get_conten ts('preg_test.t xt');
echo preg_match("#(. *?)[\r\n]+ddddddddddddd# s",$contents ) ? 'is
equal' : 'is not equal';
?>
Here's preg_test.txt:
http://www.geocities.com/terra1024/preg_test.txt
(it's a malformed part of a postscript file, in case you're curious)
My question is... when I remove the s modifier, preg_match returns
true. When the s modifier is there, it returns false. I'm not really
sure why this is. The s modifier means that . includes new lines and
carriage returns. In either case, it seems like it should match.

Hmmmz, they both match here in PHP 5.1.4, PCRE Library Version 6.6
06-Feb-2006, with or without the modifier. What version are you using?
PHP 5.2.0 (cli).

Feb 5 '07 #3
Rik
yawnmoth <te*******@yaho o.comwrote:
On Feb 5, 2:13 pm, Rik <luiheidsgoe... @hotmail.comwro te:
>yawnmoth<terra 1...@yahoo.comw rote:
Say I have the following script:
<?php
$contents = file_get_conten ts('preg_test.t xt');
echo preg_match("#(. *?)[\r\n]+ddddddddddddd# s",$contents ) ? 'is
equal' : 'is not equal';
?>
Here's preg_test.txt:
>http://www.geocities.com/terra1024/preg_test.txt
(it's a malformed part of a postscript file, in case you're curious)
My question is... when I remove the s modifier, preg_match returns
true. When the s modifier is there, it returns false. I'm not really
sure why this is. The s modifier means that . includes new lines and
carriage returns. In either case, it seems like it should match.

Hmmmz, they both match here in PHP 5.1.4, PCRE Library Version 6.6
06-Feb-2006, with or without the modifier. What version are you using?

PHP 5.2.0 (cli).
Hmmmz, the file you gave was the actual file you tested it with, or justa
part of it? Might be it just maxes out. I really don't have any other
ideas :(
--
Rik Wasmus
Feb 5 '07 #4
On Mon, 05 Feb 2007 11:24:30 -0800, yawnmoth <te*******@yaho o.comwrote:
Say I have the following script:

<?php
$contents = file_get_conten ts('preg_test.t xt');
echo preg_match("#(. *?)[\r\n]+ddddddddddddd# s",$contents ) ? 'is
equal' : 'is not equal';
?>

Here's preg_test.txt:

http://www.geocities.com/terra1024/preg_test.txt

(it's a malformed part of a postscript file, in case you're curious)

My question is... when I remove the s modifier, preg_match returns
true. When the s modifier is there, it returns false. I'm not really
sure why this is. The s modifier means that . includes new lines and
carriage returns. In either case, it seems like it should match.

Any ideas as to why it doesn't?
This is a very inefficient regex for a large amount of data. Since you are
using the lazy asterisk with the dot, the regex engine immediately starts
backtracking throughout the search. It would be easier to specify the
amount of d's through the {} quantifier, not hardcoding.

Is there a reason you capture all the content before the CRLF and d
portion of the pattern? It looks like you're merely testing if any
whitespace and 13 d's exist. If that's the case, you could just use the
strstr() function. If you want everything except the whitespace and d's,
then use substr().

--
Curtis, http://dyersweb.com
Feb 7 '07 #5
On Feb 5, 4:03 pm, Rik <luiheidsgoe... @hotmail.comwro te:
yawnmoth<terra1 ...@yahoo.comwr ote:
On Feb 5, 2:13 pm, Rik <luiheidsgoe... @hotmail.comwro te:
<snip>
Hmmmz, the file you gave was the actual file you tested it with, or just a
part of it? Might be it just maxes out. I really don't have any other
ideas :(
Yup - that's the actual file. In testing similar files, I noted that
removing a few characters from the middle made it work just fine.
This made me think that it was maxing out, but then I tried to write a
PHP script to sorta auto-generate a more simplified file that'd
demonstrate the problem but was unable to do so.

Feb 7 '07 #6
On Feb 7, 2:50 am, Curtis <dyers...@veriz on.netwrote:
On Mon, 05 Feb 2007 11:24:30 -0800,yawnmoth<t erra1...@yahoo. comwrote:
Say I have the following script:
<?php
$contents = file_get_conten ts('preg_test.t xt');
echo preg_match("#(. *?)[\r\n]+ddddddddddddd# s",$contents ) ? 'is
equal' : 'is not equal';
?>
Here's preg_test.txt:
http://www.geocities.com/terra1024/preg_test.txt
(it's a malformed part of a postscript file, in case you're curious)
My question is... when I remove the s modifier, preg_match returns
true. When the s modifier is there, it returns false. I'm not really
sure why this is. The s modifier means that . includes new lines and
carriage returns. In either case, it seems like it should match.
Any ideas as to why it doesn't?

This is a very inefficient regex for a large amount of data. Since you are
using the lazy asterisk with the dot, the regex engine immediately starts
backtracking throughout the search. It would be easier to specify the
amount of d's through the {} quantifier, not hardcoding.

Is there a reason you capture all the content before the CRLF and d
portion of the pattern? It looks like you're merely testing if any
whitespace and 13 d's exist. If that's the case, you could just use the
strstr() function. If you want everything except the whitespace and d's,
then use substr().
I'm trying to extract fonts from *.ps files. Because the fonts can
have any name of any length (afaik), substr() isn't sufficient. That
said, I assume [^\r\n]+ would be more efficient than .*? ?

Feb 7 '07 #7
yawnmoth wrote:
On Feb 7, 2:50 am, Curtis <dyers...@veriz on.netwrote:
>On Mon, 05 Feb 2007 11:24:30 -0800,yawnmoth<t erra1...@yahoo. comwrote:
>>Say I have the following script:
<?php
$contents = file_get_conten ts('preg_test.t xt');
echo preg_match("#(. *?)[\r\n]+ddddddddddddd# s",$contents ) ? 'is
equal' : 'is not equal';
?>
Here's preg_test.txt:
http://www.geocities.com/terra1024/preg_test.txt
(it's a malformed part of a postscript file, in case you're curious)
My question is... when I remove the s modifier, preg_match returns
true. When the s modifier is there, it returns false. I'm not really
sure why this is. The s modifier means that . includes new lines and
carriage returns. In either case, it seems like it should match.
Any ideas as to why it doesn't?
This is a very inefficient regex for a large amount of data. Since you are
using the lazy asterisk with the dot, the regex engine immediately starts
backtracking throughout the search. It would be easier to specify the
amount of d's through the {} quantifier, not hardcoding.

Is there a reason you capture all the content before the CRLF and d
portion of the pattern? It looks like you're merely testing if any
whitespace and 13 d's exist. If that's the case, you could just use the
strstr() function. If you want everything except the whitespace and d's,
then use substr().
I'm trying to extract fonts from *.ps files. Because the fonts can
have any name of any length (afaik), substr() isn't sufficient. That
said, I assume [^\r\n]+ would be more efficient than .*? ?
Yeah [^\r\n]+ is definitely more efficient, as it won't cause
backtracking.

--
Curtis, http://dyersweb.com
Feb 7 '07 #8

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

Similar topics

15
2265
by: Max | last post by:
Hi, I'm a perl programmer and am trying to learn PHP. So far I have figured out most of the differences, but have not been able to find out how to do the following: When running through a loop, how can you test two separate conditions against the same $element of an array. For example, this is how I thought it would be done (similar to Perl), but it did not work:
2
1618
by: Sisnaz | last post by:
I'm working with 2005 Beta 2 and I'm sure this is a trivial question but for the life of me I can't figure out. I placed a menu navigation componet on my master page and defined the navigation url for each menu item. I then created a new page and selected my master page. The menu control has a booled "Selected" property. As long as I don't set a navigation url, the menu item selected is set to true and highlighted. If I specify a...
12
1605
by: JoeC | last post by:
I am writing a program and I would like to pass an array of objects to a function and from that object I want to return a valuse to that function how do I do it? Here is what I have: terrain * t; <- an array of different kinds of terrain. This is the line of code: int mod = t->getDef();
1
1609
by: Mark Huebner | last post by:
If I have a class C that contains a private variable (property) V and private function T and T is executed within C as a separate thread, does thread T have access to private variable (property) V in the instance of class C? It appears to but another person has suggested that this is dangerous and that global variables should be defined in a separate class with the static type modifer.
6
1359
by: =?ISO-8859-1?Q?Feij=F3?= | last post by:
I'm very new to Regex, I've been strugling a lot to use it, hard to find good material :) I just need to find all matchs for something like this: D00:00:00:00 leter D, following by 4 sequences of 2 digits separated by : (2 points) How can I do that?
1
9015
by: WebCM | last post by:
There are lots of problems with XHTML parsing in PHP by XML functions. I've just solved most of them. However, how to get value of attribute with namespace? <input type="checkbox" id="something" f3:var="config.item" /> <?php foreach(xpath('//input') as $item) echo $item; ?>
2
2215
by: Sudhakar | last post by:
A) validating username in php as part of a registration form a user fills there desired username and this is stored in a mysql. there are certain conditions for the username. a) the username should only begin either letters or numbers, and Underscore character example = user123, 123user, u_ser123, user_123 = completely case insensitive
3
177
by: Jeff | last post by:
I'm parsing this: name="value" and sometimes it looks like this: name2="value2 without the closing '"'. I don't want to capture the end quote.
1
1847
by: Daniel | last post by:
Hello, It was my understanding that when the PCRE module was loaded in php that constants would be available that were built in to that module. For example, I need to use some flags with my regular expression, but they don't seem to be loaded. Here's an example: var_dump(PCRE_MULTILINE); var_dump(PCRE_DOTALL); var_dump(PCRE_MULTILINE | PCRE_DOTALL);
0
8231
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
8168
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8672
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...
1
8330
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8471
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
7153
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
5561
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
4167
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1474
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.