Forum Moderators: coopster

Message Too Old, No Replies

replace 0 in front of other number

         

helenp

12:56 pm on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi I am trying to take away the 0 before the dates.

Is there a way to put a sign in for any number?
not to have 9 diferents str_replaces

$arrival_display = str_replace("01-", "1-", $arrival_display);
$arrival_display = str_replace("02-", "2-", $arrival_display);
and so on until 9

niels

1:04 pm on Jan 22, 2006 (gmt 0)

10+ Year Member



There are parameters that do that for you.

[php.net...]

j - Day of the month without leading zeros

n - Numeric representation of a month, without leading zeros

i - Minutes with leading zeros

etc etc

maccas

1:13 pm on Jan 22, 2006 (gmt 0)

10+ Year Member



ltrim [uk2.php.net], will remove all the 0's before another character.
$arrival_display = ltrim($arrival_display, "0");

helenp

1:13 pm on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes I know,
but donīt know if can be used in this case,
it is not question of an local date or any calculated date,
it is an date from an form,
so I have the var $arrival_display = $day .'-'. $monthyear[1] .'-'. $monthyear[0];
I could always put 9 str_replaces in of course.

maccas

1:19 pm on Jan 22, 2006 (gmt 0)

10+ Year Member



If you are only going from 01 - 09 you only need to replace the 0 in one str_replace

$arrival_display = str_replace("0", "", $arrival_display);

helenp

1:25 pm on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Maccas,
that works perfect, expect that it only take away the first 0 and leave me with a date like this;
1-02-2006

helenp

1:27 pm on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



[quote="maccas"]If you are only going from 01 - 09 you only need to replace the 0 in one str_replace
$arrival_display = str_replace("0", "", $arrival_display); [/quote]
No, that takes away the cero in the year,
the date format displayed by the form is:
01-02-2006
and I want to take away the cero in day and month before any other number

niels

1:30 pm on Jan 22, 2006 (gmt 0)

10+ Year Member



$day = ltrim($day, "0");
$monthyear1 = ltrim($monthyear[1], "0");

$arrival_display = $day .'-'. $monthyear1 .'-'. $monthyear[0];

helenp

1:46 pm on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks Niels,
but dont work

maccas

1:49 pm on Jan 22, 2006 (gmt 0)

10+ Year Member



$arrival_display = ltrim($arrival_display, "0");
$arrival_display = str_replace("-0", "-", $arrival_display);

niels

1:58 pm on Jan 22, 2006 (gmt 0)

10+ Year Member



Yep that should work, good thinking maccas ;)

helenp

1:58 pm on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



lol maccas that works perfect,
you are just an crack.....
thanks a lot,
I been trying everything I could imagine.

helenp

2:00 pm on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



and thanks Niels.