Re: Best way to split a string of numbers into segments.
| From: | Mike | Date: | Tue, 02 Dec 2003 13:25:31 +0000 |
| Subject: | Re: Best way to split a string of numbers into segments. | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-171574@lists.php.net to get a copy of this message | ||
preg_match should do it...
$mydate = "20031202";
$date = array();
preg_match("/(\d{4})(\d{2})(\d{2})/", $mydate, $date);
print_r($date);
substr would be much quicker though
On Tue, 2003-12-02 at 13:14, Tom wrote:
> Hi.
>
> Is there an easy, non expensive way to do the perl-equivalent of:
> $date=20031202;
> ($year, $month, $day) = ($date =~ /(\d{4})(\d{2})(\d{2})/;
>
> I looked through the preg_* functions online, but couldn't see anything
> to help me. Am I stuck with substr() :P ?
>
> Thanks.