Re: Comparing values / Regex ?
| From: | Ben Ramsey | Date: | Sun, 21 Mar 2004 03:56:27 +0000 |
| Subject: | Re: Comparing values / Regex ? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-181067@lists.php.net to get a copy of this message | ||
Please reply to the list so that everyone may benefit from your questions.
--- Ben Ramsey <lists@benramsey.com> wrote:Yes, it's proper code. See the manual for more details. http://www.php.net/manual/en/language.operators.comparison.phpHere's my take on it. Pull all your values into one long string:(cut)if (($timestamp = strtotime($date_string)) === -1) {Is that an error - Or propper PHP code ? Ive seen $a == 34 etc - with TWO equals signs. - But havnt seen it with 3 before.// Not a valid date; do some error reportinghere } else {// It is a valid date, $timestamp is now avalid Unix// timestamp of $date_string; use it likebelow:echo date("m/d/Y", $timestamp);}
- Has PHP got 'regex' capability - & comparing text case IN-sensitivly ?? IE "Cat" equals "CaT" equals "cat" equals "CAT".. Also "Cat in the hat" is TRUE - if I 'regex' & want to see if 'Cat' is in the string (case in-sensitive)...Indeed. PHP does have regex capability. You should take a good look at the manual. It will answer all of your questions. Perl-compatible regular expressions: http://www.php.net/pcre POSIX Extended regular expressions: http://www.php.net/regex I would suggest using PCRE. There is a increased speed performance difference, I believe. You can perform case insensitive and case sensitive searches with PCRE. Just read the manual, and ask here if you have any questions with code after that. Also, note that ("cat" == "cat") but ("Cat" != "CaT"). However, I wouldn't do a string comparison like that, though PHP is definately capable of it. I would use strcmp() or strcasecmp(), the latter of which is case insensitive. Check the manual for their usage, and note that they return zero (0) on true. -- Regards, Ben Ramsey http://benramsey.com http://www.phpcommunity.org/wiki/People/BenRamsey