Re: [PHP] preg_match() returns false but no documentation why

2007-05-31 Thread Richard Lynch
On Wed, May 30, 2007 4:25 pm, Jared Farrish wrote:
 On 5/30/07, Richard Lynch [EMAIL PROTECTED] wrote:

 If you can't find them documented, print them out:

 echo PREG_NO_ERROR: ', PREG_NO_ERROR, ';


 Doh!

 PREG_NO_ERROR: 0
 PREG_INTERNAL_ERROR: 1
 PREG_BACKTRACK_LIMIT_ERROR: 2
 PREG_RECURSION_LIMIT_ERROR: 3
 PREG_BAD_UTF8_ERROR: 4

 So apparently, PREG_NO_ERROR is synonymous for you need delimiters,
 egghead.

I think the error mechanism you are checking never even had a chance
to kick in...

It's kind of like an in-flight warning system for an airplane that
never got off the ground...  It's going to keep saying no error
while the plane burns to a cinder if it never got turned on in the
first place as it never got in the air.

preg_match(/^ldap(s)?:\/\/([a-zA-Z0-9-])+\.[a-zA-Z.]{2,5}$/,$this-server)

 Try using | instead of / for your delimiter, so that you don't have
 to
 dink around with escaping the / in the pattern...


 You only have to escape / if  it's part if it's the pattern
 delimiter?

 Makes the code less cluttered and more clear.


 Fo' sho'.

Yup.

You only need to escape the delimiter you chose if it's in the pattern.

Or, looking at it from the pattern point of view:  Pick a delimiter
you are unlikely to ever need in the pattern, so you won't need to
escape it.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match() returns false but no documentation why

2007-05-31 Thread Richard Lynch
On Wed, May 30, 2007 5:04 pm, Jim Lucas wrote:
 btw: why is there a period in the second pattern?  Also, why are you
 allowing for uppercase letters
 when the RFC's don't allow them?

LDAP URL domain can't be ALL CAPS?!

Last I heard, domain names were case-insensitive in every other URL...

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] preg_match() returns false but no documentation why

2007-05-30 Thread Jared Farrish

Hi all,

Can anybody spot why this doesn't seem to be working right? The manual (
http://us2.php.net/preg_match) says it returns false on error, but
preg_last_error() returns 0, which I assume points to the PREG_NO_ERROR
error code.

code
preg_match(^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$,$this-server)
/code

I also tried ereg(), and have searched and gone through the comments. Why
would a regex operation return false?

That may be ugly, since I've not done a lot of regex's yet. I have checked
and $this-server does insert a valid string. What I am trying to do is
validate ldap://com.com and ldaps://com.com and all valid variations of. Is
there something wrong with the regex, or am I pumping an invalid format into
preg_match()?

Incidentally, I stole the last piece (after ldaps://) off a regex for email
addresses (from SitePoint,
http://www.sitepoint.com/article/regular-expressions-php).

Thanks!

--
Jared Farrish
Intermediate Web Developer
Denton, Tx

Abraham Maslow: If the only tool you have is a hammer, you tend to see
every problem as a nail. $$


Re: [PHP] preg_match() returns false but no documentation why

2007-05-30 Thread Richard Lynch
On Wed, May 30, 2007 12:33 pm, Jared Farrish wrote:
 Hi all,

 Can anybody spot why this doesn't seem to be working right? The manual
 (
 http://us2.php.net/preg_match) says it returns false on error, but
 preg_last_error() returns 0, which I assume points to the
 PREG_NO_ERROR
 error code.

 code
 preg_match(^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$,$this-server)

You are missing the start/end delimiters is your first problem...

 /code

 I also tried ereg(), and have searched and gone through the comments.
 Why
 would a regex operation return false?

It would return false if your string doesn't match the expression.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match() returns false but no documentation why

2007-05-30 Thread Jared Farrish

On 5/30/07, Richard Lynch [EMAIL PROTECTED] wrote:

On Wed, May 30, 2007 12:33 pm, Jared Farrish wrote:

 preg_match(^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$,$this-server)

You are missing the start/end delimiters is your first problem...


Which ones? I've got the starter ^ and the closer $, so what else am I
missing?


would a regex operation return false?

It would return false if your string doesn't match the expression.



The manual claims it will return a 0 signaling 0 matches found. And then,
under Return Values, it's says very quickly:

*preg_match()* returns *FALSE* if an error occurred.

If it's not returning ANYTHING I'm assuming it's faulting, but the calling
the error function returns 0 (kind've ironic, really...).

--
Jared Farrish
Intermediate Web Developer
Denton, Tx

Abraham Maslow: If the only tool you have is a hammer, you tend to see
every problem as a nail. $$


Re: [PHP] preg_match() returns false but no documentation why

2007-05-30 Thread Stut

Jared Farrish wrote:

On 5/30/07, Richard Lynch [EMAIL PROTECTED] wrote:

On Wed, May 30, 2007 12:33 pm, Jared Farrish wrote:

 preg_match(^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$,$this-server)

You are missing the start/end delimiters is your first problem...


Which ones? I've got the starter ^ and the closer $, so what else am I
missing?


You need delimiters around the regex, as stated in the documentation.

preg_match(/^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/,$this-server)

Although you don't need to use slashes, you can use any character you 
want but you must escape it in if it appears in the regex.



would a regex operation return false?

It would return false if your string doesn't match the expression.



The manual claims it will return a 0 signaling 0 matches found. And then,
under Return Values, it's says very quickly:

*preg_match()* returns *FALSE* if an error occurred.

If it's not returning ANYTHING I'm assuming it's faulting, but the calling
the error function returns 0 (kind've ironic, really...).


It will return false on an error, such as not having matching delimiters 
aroung the regex.


The error function may retuyrn 0, but which of the following constants 
is defined as 0?


PREG_NO_ERROR
PREG_INTERNAL_ERROR
PREG_BACKTRACK_LIMIT_ERROR
PREG_RECURSION_LIMIT_ERROR
PREG_BAD_UTF8_ERROR

-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match() returns false but no documentation why

2007-05-30 Thread Richard Lynch


On Wed, May 30, 2007 3:06 pm, Jared Farrish wrote:
 On 5/30/07, Richard Lynch [EMAIL PROTECTED] wrote:
 On Wed, May 30, 2007 12:33 pm, Jared Farrish wrote:
 
  preg_match(^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$,$this-server)

 You are missing the start/end delimiters is your first problem...

 Which ones? I've got the starter ^ and the closer $, so what else
 am I
 missing?

Whatever character you want to use:

|^ldap(s)?//[a-zA-Z0-9-]*\\.[a-zA-Z.]{2,5}$|
%^ldap(s)?//[a-zA-Z0-9-]*\\.[a-zA-Z.]{2,5}$%
#^ldap(s)?//[a-zA-Z0-9-]*\\.[a-zA-Z.]{2,5}$#


 would a regex operation return false?

 It would return false if your string doesn't match the expression.


 The manual claims it will return a 0 signaling 0 matches found. And
 then,
 under Return Values, it's says very quickly:

 *preg_match()* returns *FALSE* if an error occurred.

 If it's not returning ANYTHING I'm assuming it's faulting, but the
 calling
 the error function returns 0 (kind've ironic, really...).

Use === to distinguish FALSE from 0, which are not the same.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match() returns false but no documentation why

2007-05-30 Thread Jared Farrish

On 5/30/07, Stut [EMAIL PROTECTED] wrote:


You need delimiters around the regex, as stated in the documentation.

preg_match(/^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/,$this-server)

Although you don't need to use slashes, you can use any character you
want but you must escape it in if it appears in the regex.



Oh! You know, I had looked over those a couple times already. Can't say why
I didn't see them.

It will return false on an error, such as not having matching delimiters

aroung the regex.

The error function may retuyrn 0, but which of the following constants
is defined as 0?

PREG_NO_ERROR
PREG_INTERNAL_ERROR
PREG_BACKTRACK_LIMIT_ERROR
PREG_RECURSION_LIMIT_ERROR
PREG_BAD_UTF8_ERROR



I don't know, I'm assuming it means no error... I couldn't see anywhere
where it mentioned what was what.

Now that I'm looking at it again, I see it's 5.2 or greater, and I think
we're on 5.1 or something. Although, it seems like it would have a fatal
error if I call a function that doesn't exist...


Use === to distinguish FALSE from 0, which are not the same.


I realize they're not the same. What I was saying was that false is not
the stated return value if it's not found. If it's not printing a zero,
shouldn't that mean it's returning false?

preg_match(/^ldap(s)?:\/\/([a-zA-Z0-9-])+\.[a-zA-Z.]{2,5}$/,$this-server)

Now when I add the slashes, I get zero, even though I give it a real value
that should return 1. *sigh*

--
Jared Farrish
Intermediate Web Developer
Denton, Tx

Abraham Maslow: If the only tool you have is a hammer, you tend to see
every problem as a nail. $$


Re: [PHP] preg_match() returns false but no documentation why

2007-05-30 Thread Richard Lynch
On Wed, May 30, 2007 3:25 pm, Jared Farrish wrote:
 On 5/30/07, Stut [EMAIL PROTECTED] wrote:

 You need delimiters around the regex, as stated in the
 documentation.

 preg_match(/^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/,$this-server)

 Although you don't need to use slashes, you can use any character
 you
 want but you must escape it in if it appears in the regex.


 Oh! You know, I had looked over those a couple times already. Can't
 say why
 I didn't see them.

 It will return false on an error, such as not having matching
 delimiters
 aroung the regex.

 The error function may retuyrn 0, but which of the following
 constants
 is defined as 0?

 PREG_NO_ERROR
 PREG_INTERNAL_ERROR
 PREG_BACKTRACK_LIMIT_ERROR
 PREG_RECURSION_LIMIT_ERROR
 PREG_BAD_UTF8_ERROR


 I don't know, I'm assuming it means no error... I couldn't see
 anywhere
 where it mentioned what was what.

If you can't find them documented, print them out:

echo PREG_NO_ERROR: ', PREG_NO_ERROR, ';

Or even:
var_dump(PREG_NO_ERROR);

 Now that I'm looking at it again, I see it's 5.2 or greater, and I
 think
 we're on 5.1 or something. Although, it seems like it would have a
 fatal
 error if I call a function that doesn't exist...

The function exists.

The constants may not...

 Use === to distinguish FALSE from 0, which are not the same.

 I realize they're not the same. What I was saying was that false is
 not
 the stated return value if it's not found. If it's not printing a
 zero,
 shouldn't that mean it's returning false?

 preg_match(/^ldap(s)?:\/\/([a-zA-Z0-9-])+\.[a-zA-Z.]{2,5}$/,$this-server)

Try using | instead of / for your delimiter, so that you don't have to
dink around with escaping the / in the pattern...

Makes the code less cluttered and more clear.

Unless you have | in your pattern, or need the Regex branch '|'
character.

 Now when I add the slashes, I get zero, even though I give it a real
 value
 that should return 1. *sigh*

You may want \\. for the . in dot com

Download and play with The Regex Coach

It does pretty color syntax highlighting of the target string and your
regex to show you what's going on, as well as a slow-motion instant
replay to step through it piece by piece.

Doesn't always match PHP perfectly, as it's for Perl, but, man, that
tool alone has saved me a few hundred hours.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match() returns false but no documentation why

2007-05-30 Thread Jared Farrish

On 5/30/07, Richard Lynch [EMAIL PROTECTED] wrote:


If you can't find them documented, print them out:

echo PREG_NO_ERROR: ', PREG_NO_ERROR, ';



Doh!

PREG_NO_ERROR: 0
PREG_INTERNAL_ERROR: 1
PREG_BACKTRACK_LIMIT_ERROR: 2
PREG_RECURSION_LIMIT_ERROR: 3
PREG_BAD_UTF8_ERROR: 4

So apparently, PREG_NO_ERROR is synonymous for you need delimiters,
egghead.



preg_match(/^ldap(s)?:\/\/([a-zA-Z0-9-])+\.[a-zA-Z.]{2,5}$/,$this-server)

Try using | instead of / for your delimiter, so that you don't have to
dink around with escaping the / in the pattern...



You only have to escape / if  it's part if it's the pattern delimiter?

Makes the code less cluttered and more clear.


Fo' sho'.



 Now when I add the slashes, I get zero, even though I give it a real
 value
 that should return 1. *sigh*

You may want \\. for the . in dot com



Ok, I tried:

preg_match(|^ldap(s)?://([a-zA-Z0-9-])+\.[a-zA-Z.]{2,5}$|,$this-server)
preg_match(|^ldap(s)?://([a-zA-Z0-9-])+\\.[a-zA-Z.]{2,5}$|,$this-server)
preg_match(|^ldap(s)?:\/\/([a-zA-Z0-9-])+\\.[a-zA-Z.]{2,5}$|,$this-server)

using: $this-server = ldap://www.example.com;;

No luck. I'll the try tool you referred to; I have been using
regular-expressions.info for information.

Download and play with The Regex Coach


It does pretty color syntax highlighting of the target string and your
regex to show you what's going on, as well as a slow-motion instant
replay to step through it piece by piece.



Oooh, pretty colors! Stepping through sounds interesting. I'll have to check
it out.

Thanks!

--
Jared Farrish
Intermediate Web Developer
Denton, Tx

Abraham Maslow: If the only tool you have is a hammer, you tend to see
every problem as a nail. $$


Re: [PHP] preg_match() returns false but no documentation why

2007-05-30 Thread Jim Lucas

Stut wrote:

Jared Farrish wrote:

On 5/30/07, Richard Lynch [EMAIL PROTECTED] wrote:

On Wed, May 30, 2007 12:33 pm, Jared Farrish wrote:

 preg_match(^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$,$this-server)

You are missing the start/end delimiters is your first problem...


Which ones? I've got the starter ^ and the closer $, so what else 
am I

missing?


You need delimiters around the regex, as stated in the documentation.

preg_match(/^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/,$this-server)

This isn't going to work, the op has two forward slashes in the string that he 
is wanting to match with.

The op will need to use something other than forward slashes.

so, this is going to match:
ldap://testing123.com   TRUE
ldap://www.testing-123.com  FALSE
ldap://testing123.com.ukFALSE
ldap://testing123.or.us TRUE

preg_match('|^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$|', $this-server )

I also recommend using single quotes instead of double quotes here.

btw: why is there a period in the second pattern?  Also, why are you allowing for uppercase letters 
when the RFC's don't allow them?


Just my thoughts



Although you don't need to use slashes, you can use any character you 
want but you must escape it in if it appears in the regex.



would a regex operation return false?

It would return false if your string doesn't match the expression.



The manual claims it will return a 0 signaling 0 matches found. And 
then,

under Return Values, it's says very quickly:

*preg_match()* returns *FALSE* if an error occurred.

If it's not returning ANYTHING I'm assuming it's faulting, but the 
calling

the error function returns 0 (kind've ironic, really...).


It will return false on an error, such as not having matching delimiters 
aroung the regex.


The error function may retuyrn 0, but which of the following constants 
is defined as 0?


PREG_NO_ERROR
PREG_INTERNAL_ERROR
PREG_BACKTRACK_LIMIT_ERROR
PREG_RECURSION_LIMIT_ERROR
PREG_BAD_UTF8_ERROR

-Stut




--
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Unknown

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match() returns false but no documentation why

2007-05-30 Thread Crayon Shin Chan
On Thursday 31 May 2007 01:33, Jared Farrish wrote:

 Can anybody spot why this doesn't seem to be working right? The manual
 ( http://us2.php.net/preg_match) says it returns false on error, but
 preg_last_error() returns 0, which I assume points to the
 PREG_NO_ERROR error code.

 code
 preg_match(^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$,$this-server)
 /code

 I also tried ereg(), and have searched and gone through the comments.
 Why would a regex operation return false?

If you check your error log you'll find:

Warning: preg_match(): No ending delimiter '^' found in xxx.php on line xx

IMO that shouldn't be a warning, it should be an error that halts 
execution so people wouldn't go looking for a non-existant 
preg_last_error() when preg_match() did not even run.

-- 
Crayon

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php