php-general Digest 28 Jul 2013 17:14:49 -0000 Issue 8312
Topics (messages 321726 through 321730):
Re: From 24/7/2013 to 2013-07-24
321726 by: Jim Giner
321727 by: Robert Cummings
321728 by: Tamara Temple
321729 by: Tamara Temple
POST action
321730 by: iccsi
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
On 7/26/2013 5:29 PM, Robert Cummings wrote:
On 13-07-26 04:38 PM, jomali wrote:
On Fri, Jul 26, 2013 at 1:08 PM, Robert Cummings
<rob...@interjinn.com>wrote:
On 13-07-26 11:42 AM, jomali wrote:
On Fri, Jul 26, 2013 at 5:18 AM, Karl-Arne Gjersøyen
<karlar...@gmail.com
wrote:
Below is something I try that ofcourse not work because of rsosort.
Here is my code:
-----------------------
$lagret_dato = $_POST['lagret_dato'];
foreach($lagret_dato as $dag){
$dag = explode("/", $dag);
rsort($dag);
$dag = implode("-", $dag);
var_dump($dag);
What I want is a way to rewrite contents of a variable like this:
From 24/7/2013 to 2013-07-24
Is there a way in PHP to do this?
Thank you very much.
Karl
$conv_date = str_replace('/', '-','24/7/2013');
echo date('Y-m-d', strtotime($conv_date));
Result: 2013-07-24
It would be better if you reformatted first since this is ambiguous when
you have the following date:
6/7/2013
Here's a completely unambiguous solution:
<?php
$old = '24/7/2013';
$paddy = function( $bit ){ return str_pad( $bit, 2, '0',
STR_PAD_LEFT
); };
$new = implode( '-', array_map( $paddy, array_reverse( explode(
'/',
$old ) ) ) );
echo $new."\n";
?>
Cheers,
Rob.
The original question was about reformatting a European (Day/Month/Year)
date. Your solution does not address this problem. Mine assumes the
European date format explicitly.
Jomali,
Your solution is broken. The original poster requested the following:
>>>> What I want is a way to rewrite contents of a variable like this:
>>>>
>>>> From 24/7/2013 to 2013-07-24
Your solution makes use of the strtodate(). A useful strategy EXCEPT (as
you have already noted) the date follows the European formatting rules
of dd/mm/yyyy since the 24 as the first number makes that obvious.
HOWEVER, you failed to realize the following (from the PHP online manual):
Dates in the m/d/y or d-m-y formats are disambiguated by looking
at the separator between the various components: if the separator
is a slash (/), then the American m/d/y is assumed; whereas if
the separator is a dash (-) or a dot (.), then the European d-m-y
format is assumed.
And so, as soon as an abiguous date arises, the solution will be
incorrect because strtotime() will presume an American format due to the
appearance of the slash instead of the hyphen. It is dangerous to rely
on magical functions like strtotime() unless you completely understand
how ambiguity is resolved.
Another solution that was posted only re-ordered the elements and you
likely noticed that there is a single digit 7 in the source date and in
the response date it has been 0 padded to conform to the standard
yyyy-mm-dd date format. The other solution does not do this and so it is
also incorrect.
And so it follows, that my solution, thus far, is the only solution
posted that actually meets the requirements. Why you think my solution
does not perform is beyond me since a simple run of the code would
output the correct answer (yes I did test)-- mine also presumes the
European ordering for all input with components separated by a slash.
Cheers,
Rob.
And my solution doesn't work?
--- End Message ---
--- Begin Message ---
On 13-07-26 05:33 PM, Jim Giner wrote:
On 7/26/2013 5:29 PM, Robert Cummings wrote:
And so it follows, that my solution, thus far, is the only solution
posted that actually meets the requirements. Why you think my solution
does not perform is beyond me since a simple run of the code would
output the correct answer (yes I did test)-- mine also presumes the
European ordering for all input with components separated by a slash.
Cheers,
Rob.
>
And my solution doesn't work?
I don't see any padding happening in your solution. Your solution produced:
2013-7-24
The required solution is:
2013-07-24
:)
Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.
--- End Message ---
--- Begin Message ---
On Jul 26, 2013, at 4:18 AM, Karl-Arne Gjersøyen <karlar...@gmail.com> wrote:
> Below is something I try that ofcourse not work because of rsosort.
> Here is my code:
> -----------------------
> $lagret_dato = $_POST['lagret_dato'];
> foreach($lagret_dato as $dag){
>
> $dag = explode("/", $dag);
> rsort($dag);
You want to reverse the array, not sort it :) array_reverse().
> $dag = implode("-", $dag);
> var_dump($dag);
>
> What I want is a way to rewrite contents of a variable like this:
>
> From 24/7/2013 to 2013-07-24
>
> Is there a way in PHP to do this?
>
> Thank you very much.
>
> Karl
Also, I thought the locale for European countries used periods as separators,
not slashes; slashes for North America…
*shrug*
--- End Message ---
--- Begin Message ---
augh, apologies; i didn't see all the other replies….
--- End Message ---
--- Begin Message ---
<form action="action.php" method="post">
<p>Your name: <input type="text" name="name" /></p>
<p>Your age: <input type="text" name="age" /></p>
<p><input type="submit" /></p>
</form>In the PHP tutorial manual, it says that we can have post action to
the form itself just like above coding.I would like to know in the real
projects, can we have action to the same PHP file, since that we only need
have one filebut not 2 files foe POST request,Your help and information is
great appreciated,regards,Iccsi,
--- End Message ---