473,503 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ereg question

I have a little problem with ereg (eregi) in PHP - in some cases it behaves
differently than I expect and I don`t know if my expectations are strange or
there is any "syntax subtlety" I have missed.

I want to find a value for key1 in string:

key1=>value_of key1[EOT]key2=>other_value[EOT]key3=>value[3][EOT]

and I use an ereg pattern

ereg("key1=>([[:print:][:space:]]*)\[EOT\]",$line,$regs);

unfortunately ereg match differs from "value_of key1", which I wanted to
receive. Ereg finds the last apperance of [EOT] in string $line and the
value of $regs[1] is

"key1=>value_of key1[EOT]key2=>other_value[EOT]key3=>value[3]"

Can I achieve an effect, that ereg matches the first occurence of [EOT] and
as a result I`'ll get "value_of key1" as a result?

Thanks for help
Rafal
Jul 17 '05 #1
3 2390
Rafal Zak wrote:
I have a little problem with ereg (eregi) in PHP - in some cases it behaves
differently than I expect and I don`t know if my expectations are strange or
there is any "syntax subtlety" I have missed.

I want to find a value for key1 in string:

key1=>value_of key1[EOT]key2=>other_value[EOT]key3=>value[3][EOT]

and I use an ereg pattern

ereg("key1=>([[:print:][:space:]]*)\[EOT\]",$line,$regs);

unfortunately ereg match differs from "value_of key1", which I wanted to
receive. Ereg finds the last apperance of [EOT] in string $line and the
value of $regs[1] is

"key1=>value_of key1[EOT]key2=>other_value[EOT]key3=>value[3]"

Can I achieve an effect, that ereg matches the first occurence of [EOT] and
as a result I`'ll get "value_of key1" as a result?


The * in "([[:print:][:space:]]*)" will also match the first "[EOT]"
because they are all print characters. You'd need to use a negative
look-ahead or something along those lines, but I do not know if that is
supported in ereg patterns....

--
Justin Koivisto - sp**@koivi.com
http://www.koivi.com
Jul 17 '05 #2

unfortunately ereg match differs from "value_of key1", which I wanted to
receive. Ereg finds the last apperance of [EOT] in string $line and the
value of $regs[1] is

"key1=>value_of key1[EOT]key2=>other_value[EOT]key3=>value[3]"

Can I achieve an effect, that ereg matches the first occurence of [EOT] and
as a result I`'ll get "value_of key1" as a result?

Thanks for help
Rafal


The match is called "greedy" because it grabs the biggest chunk of
characters that meet your condition (print or space).

add to that condition a [^\[EOT\]] and you should get what you want
Jul 17 '05 #3
.oO(Matthew Crouch)
The match is called "greedy" because it grabs the biggest chunk of
characters that meet your condition (print or space).

add to that condition a [^\[EOT\]] and you should get what you want


Why not simply use preg_match with the modifier U?

Micha
Jul 17 '05 #4

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

Similar topics

5
2874
by: bonehead | last post by:
Greetings, I'd like to add somee error handling to a password field: if the password is fewer than 5 characters or greater than 15 characters I'd like to trap it. Special characters such as ^...
1
2334
by: Stefan Gangefors | last post by:
I'm trying to figure out what I'm doing wrong when using ereg(). This is my regexp: ereg("^]$", "]"); and that does'n work, but this does: ereg("^$", "[");
9
2402
by: Fiore Alessandro | last post by:
Hi all I've installed Apache 2.0.48 and PHP 4.3.4 on a workstation running Linux, RedHat 9.0. Let's consider the following piece of code: $patt = "{3}/{6}"; if...
3
20966
by: Martin Lucas-Smith | last post by:
Is there some way of using ereg to detect when certain filename extensions are supplied and to return false if so, WITHOUT using the ! operator before ereg () ? I have an API that allows as an...
2
4439
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, --
3
1600
by: Dynamo | last post by:
Hi, Thanks to all who replied to original posting.As a direct result of now gaining a better understanding of regular expressions, instead of trying to use other peoples scripts I am now trying to...
3
1591
by: news | last post by:
I'm trying to make sure a form has only one or two digits in either of two fields. I looked at php.net and http://www.regular-expressions.info/reference.html and this is what I put together, but...
3
2233
by: rachellara1979 | last post by:
Hi, new to PHP and to this group, so very sorry if this is simple or has been covered before. Basically want to check that a user and password (entered in a previous page) only has characters but...
18
2005
by: yawnmoth | last post by:
Say I have the following script: <? $string = 'test'; if (eregi("^+$",$string)) { echo 'matches!'; } else {
0
7271
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
7319
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...
0
7449
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...
0
5570
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,...
0
4666
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...
0
3160
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...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.