Re: Problems with split

From: Date: Tue, 14 Aug 2001 00:45:27 +0000
Subject: Re: Problems with split
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-62546@lists.php.net to get a copy of this message
>--- >$invdate = "14.8.2001"; >echo "$invdate\n"; >list($day, $month, $year) = split(".", $invdate); >echo "$year-$month-$day"; >--- split uses Regular Expressions. This means that a whole slew of characters like [, ], |, \, $, ^, and [drum roll please] '.' are "special". Specifically, "." means "any damn character at all". You could 'escape' the "." character with file://\\. and all would be good But, it would be way easier (and more efficient if you're doing a lot of these) to use http://php.net/explode instead, wherein *NO* characters are "special" (other than the usual ones for PHP itself, of course.) As a bonus, you save yourself the headache of trying to understand Regular Expressions. :-) list($day, $month, $year) = explode(".", $invdate); Besides, blowing things up is much more fun than just chopping them with an axe :-) :-) :-) -- WARNING richard@zend.com address is an endangered species -- Use ceo@l-i-e.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm

« previous php.general (#62546) next »