Connecting Tech Pros Worldwide Forums | Help | Site Map

Ereg i

Fiore Alessandro
Guest
 
Posts: n/a
#1: Jul 17 '05
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

Maurizio Palesi
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Ereg i


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:[color=blue]
> 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[/color]

Alvaro G Vicario
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Ereg i


*** Fiore Alessandro wrote/escribió (23 Jan 2004 00:53:53 -0800):[color=blue]
> if (ereg("^$patt$",$matricola))
> echo "foo1";
> else
> echo "foo2";
>
> Why the output is "foo1"? It should be "foo2".[/color]

What's the value of $matricula?

--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Maurizio Palesi
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Ereg i


Alvaro G Vicario wrote:[color=blue]
>
> What's the value of $matricula?
>[/color]
$mapricula="123/456789"

John Dunlop
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Ereg i


Maurizio Palesi wrote:
[color=blue]
> $matr = "123/456789",
> $patt = "[0-9]{3}/[0-9]{6}";
>
> if (ereg("^$patt$",$matr))
> echo "foo1";
> else
> echo "foo2";
>
> Why the output is foo2?[/color]

It's not.

--
Jock
Alvaro G Vicario
Guest
 
Posts: n/a
#6: Jul 17 '05

re: Ereg i


*** Maurizio Palesi wrote/escribió (Fri, 23 Jan 2004 13:52:45 +0100):[color=blue]
> $mapricula="123/456789"[/color]

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
--
Peacenik
Guest
 
Posts: n/a
#7: Jul 17 '05

re: Ereg i


"Maurizio Palesi" <mpalesi@yahoo.it> wrote in message
news:buqnkd$ba6$1@newsfeed.cineca.it...[color=blue]
> 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?[/color]

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

--
Peacenik


Sebastiaan
Guest
 
Posts: n/a
#8: Jul 17 '05

re: Ereg i


Alvaro G Vicario <alvaro_QUITAR_REMOVE@telecomputeronline.com> wrote in message news:<qt5zt2hcbnu$.1gojqwsqcvcu$.dlg@40tude.net>.. .
[color=blue]
>
> It isn't just a misspell of $matricola, is it?
>
> --[/color]

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
Savut
Guest
 
Posts: n/a
#9: Jul 17 '05

re: Ereg i


Should be foo1 the answer, what is wrong ???

Savut

"Fiore Alessandro" <fiorealessandro2000@yahoo.it> wrote in message news:b4e8a5e2.0401230053.4f37efed@posting.google.c om...[color=blue]
> 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[/color]


Sebastiaan
Guest
 
Posts: n/a
#10: Jul 17 '05

re: Ereg i


Alvaro G Vicario <alvaro_QUITAR_REMOVE@telecomputeronline.com> wrote in message news:<qt5zt2hcbnu$.1gojqwsqcvcu$.dlg@40tude.net>.. .
[color=blue]
>
> It isn't just a misspell of $matricola, is it?
>
> --[/color]

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
Closed Thread