SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: split string of numbers php
Hybrid View
-
Mar 16, 2007, 22:00 #1
- Join Date
- Apr 2005
- Posts
- 56
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
split string of numbers php
Hey If i have a string of numbers eg:
Code:$date = 200703241230
how can i split the string so i can have it like:
Code:$date_year = 2007 $date_month = 03 $date_day = 24 $date_hour = 12 $date_minute = 30
thanks in advance for your help.
munnaz
-
Mar 16, 2007, 22:04 #2
- Join Date
- Dec 2005
- Posts
- 101
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
One way you can do it (if your strings are always going to be the same length), is to use substr() and just use different offsets.
PHP Code:$date = "200703241230";
$date_year = substr($date, 0, 4);
// And so on
-
Mar 16, 2007, 23:30 #3
- Join Date
- Oct 2005
- Location
- London, UK
- Posts
- 148
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:<?php
$date = 200703241230;
preg_match('/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})$/',$date,&$results);
$year = $results[1];
$month = $results[2];
$day = $results[3];
$hour = $results[4];
$minute = $results[5];
echo "$year $month $day $hour $minute";
?>
-
Mar 17, 2007, 07:08 #4
- Join Date
- Apr 2004
- Location
- germany
- Posts
- 4,324
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:echo date("d/m/Y H:i", strtotime($date));
-
Mar 17, 2007, 16:42 #5
Bookmarks