Re: preg_match() returns false but no documentation why

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/30/07, Stut <stuttle@xxxxxxxxx> 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." $$

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux