473,395 Members | 1,568 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,395 software developers and data experts.

Ereg i

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 = "[0-9]{3}/[0-9]{6}";

if (ereg("^$patt$",$matricola))
echo "foo1";
else
echo "foo2";

Why the output is "foo1"? It should be "foo2". I 've tried the same
code
to another PHP & Apache installation (sorry but I do not remind the
version) on a windows box and it works fine.

What is the problem?

Thanks a lot in advance,
Alessandro
Jul 17 '05 #1
9 2399
Ok, Alessandro misses one line... the piece of code he refers is

$matr = "123/456789",
$patt = "[0-9]{3}/[0-9]{6}";

if (ereg("^$patt$",$matr))
echo "foo1";
else
echo "foo2";

Why the output is foo2?

Maurizio

Fiore Alessandro wrote:
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 = "[0-9]{3}/[0-9]{6}";

if (ereg("^$patt$",$matricola))
echo "foo1";
else
echo "foo2";

Why the output is "foo1"? It should be "foo2". I 've tried the same
code
to another PHP & Apache installation (sorry but I do not remind the
version) on a windows box and it works fine.

What is the problem?

Thanks a lot in advance,
Alessandro


Jul 17 '05 #2
*** Fiore Alessandro wrote/escribió (23 Jan 2004 00:53:53 -0800):
if (ereg("^$patt$",$matricola))
echo "foo1";
else
echo "foo2";

Why the output is "foo1"? It should be "foo2".


What's the value of $matricula?

--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Jul 17 '05 #3
Alvaro G Vicario wrote:

What's the value of $matricula?

$mapricula="123/456789"

Jul 17 '05 #4
Maurizio Palesi wrote:
$matr = "123/456789",
$patt = "[0-9]{3}/[0-9]{6}";

if (ereg("^$patt$",$matr))
echo "foo1";
else
echo "foo2";

Why the output is foo2?


It's not.

--
Jock
Jul 17 '05 #5
*** Maurizio Palesi wrote/escribió (Fri, 23 Jan 2004 13:52:45 +0100):
$mapricula="123/456789"


This code works for me (prints foo1):

<?
$matricola="123/456789";
$patt = "[0-9]{3}/[0-9]{6}";

if (ereg("^$patt$",$matricola))
echo "foo1";
else
echo "foo2";
?>

It isn't just a misspell of $matricola, is it?

--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Jul 17 '05 #6
"Maurizio Palesi" <mp*****@yahoo.it> wrote in message
news:bu**********@newsfeed.cineca.it...
Ok, Alessandro misses one line... the piece of code he refers is

$matr = "123/456789",
$patt = "[0-9]{3}/[0-9]{6}";

if (ereg("^$patt$",$matr))
echo "foo1";
else
echo "foo2";

Why the output is foo2?


I get "foo1" when I run it (after correcting the comma on the first line to
a semicolon).

--
Peacenik
Jul 17 '05 #7
Alvaro G Vicario <al******************@telecomputeronline.com> wrote in message news:<qt****************************@40tude.net>.. .

It isn't just a misspell of $matricola, is it?

--


In my opinion the syntax is the problem. If you substitute the line

if (ereg("^$patt$",$matricola))

with

if (!ereg($patt,$matricola)) //Notice the ! before ereg

it does what you want, namely echoing "foo2".

Hope it is what you want,
Sebastiaan
Jul 17 '05 #8
Should be foo1 the answer, what is wrong ???

Savut

"Fiore Alessandro" <fi*****************@yahoo.it> wrote in message news:b4**************************@posting.google.c om...
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 = "[0-9]{3}/[0-9]{6}";

if (ereg("^$patt$",$matricola))
echo "foo1";
else
echo "foo2";

Why the output is "foo1"? It should be "foo2". I 've tried the same
code
to another PHP & Apache installation (sorry but I do not remind the
version) on a windows box and it works fine.

What is the problem?

Thanks a lot in advance,
Alessandro

Jul 17 '05 #9
Alvaro G Vicario <al******************@telecomputeronline.com> wrote in message news:<qt****************************@40tude.net>.. .

It isn't just a misspell of $matricola, is it?

--


In my opinion the syntax is wrong. If you substitute

if (ereg("^$patt$",$matricola))

with

if (!ereg($patt,$matricola)) //Notice the ! before ereg

it does what you want, namely echoing "foo2".
Hope this helps you out,
Sebastiaan
Jul 17 '05 #10

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

Similar topics

1
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("^$", "[");
3
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
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
by: Rafal Zak | last post by:
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...
3
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
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
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
by: yawnmoth | last post by:
Say I have the following script: <? $string = 'test'; if (eregi("^+$",$string)) { echo 'matches!'; } else {
6
by: millw0rm | last post by:
why i m getting error here??? Warning: ereg(): REG_BADBR code: if(!ereg("^(.){15,400}$",$string)) { $errormsg = "- Must be more then 15 Characters & less then 400 Characters"; }
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...
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
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,...
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...
0
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...
0
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
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,...

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.