exploding a string
Posted 20 June 2006 - 01:00 PM
actualy its the day nr of the month.
when its 21 i want it to say 21st and when its 25 it has to say 25th.
so first i need to split the 2 numbers to figure out what the last one is!
there probely is another way to figure this out but i would like to know how to split that damn string.
it has no seperator so how would this be done?
Posted 20 June 2006 - 01:03 PM
<?php $string = "21"; preg_match('|[0-9]|', $string, $match); foreach ($match as $digit) echo "$digit<br />\n"; ?>
or, if you simply need to know the last character of the string, try this:
<?php $string = "21"; echo substr($string, -1); ?>
Posted 20 June 2006 - 01:15 PM
thanks you very much, you saved me lot's of time.
it so easy isn't it?
it just that you have to know it to use it.
Posted 20 June 2006 - 01:52 PM
<?php echo 'Today is the ' . date('jS') . ' of the month of ' . date('F') . ' in the year ' . date('Y') . '<br>'; $rand_month = rand(1,12); $max_days = date('t',strtotime(date('Y') . '-' . $rand_month . '-01')); $rand_day = rand(1,$max_days); $rand_year = rand(date('Y'),2037); // the date function might break in 2038! $rand_date = strtotime($rand_year . '-' . $rand_month . '-' . $rand_day); echo 'In the year ' . $rand_year . ', the ' . date('jS',$rand_date) . ' of ' . date('F',$rand_date) . ' falls on a ' . date('l',$rand_date) . '<br>'; // that's a lowercase 'L' in the last date(). ?>
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users