Jump to content

Archived

This topic is now archived and is closed to further replies.

xyn

Implode count :ll

Recommended Posts

Hey
I have a date of birth field and I wanted to implode it from it's separate fields into
one field by using implode i wanted to make it NN/NN/NNNN, so if i wanted to use
this information when changing passwords i can explode it etc.

my error:
Warning: Wrong parameter count for implode() in /home/**/func.php on line 128

my code:
[code=php:0]$doba = MakeSafe($_POST[dobd]);
$dobm = MakeSafe($_POST[dobm]);
$doby = Makesafe($_POST[doby]);
$Dob = implode('/', '$doba','$dobm','$doby');[/code]

Share this post


Link to post
Share on other sites
The [url=http://www.php.net/implode]implode()[/url] function takes an array as the second paramter, not strings. You can achieve the what you're looking for in two ways:
1)
[code]<?php
$doba = MakeSafe($_POST[dobd]);
$dobm = MakeSafe($_POST[dobm]);
$doby = Makesafe($_POST[doby]);
$Dob = implode('/', array($doba,$dobm,$doby));
?>[/code]

2)
[code]<?php
$tmp = array();
$tmp[] = MakeSafe($_POST[dobd]);
$tmp[] = MakeSafe($_POST[dobm]);
$tmp[] = Makesafe($_POST[doby]);
$Dob = implode('/', $tmp);
?>[/code]

Ken

Share this post


Link to post
Share on other sites
^ that's a whole lot of extra work for simply making a string of values seperated by a / ...sure, it might be all fancy looking, but again, this does the same thing:

[code]
<?php
$doba = MakeSafe($_POST[dobd]);
$dobm = MakeSafe($_POST[dobm]);
$doby = Makesafe($_POST[doby]);
$Dob = "$doba/$dobm/$doby";
?>
[/code]

Share this post


Link to post
Share on other sites
Yes, I know, but the OP asked about using the [b]implode()[/b] function, so I gave him examples using the function.

Of course your example can be reduced to:
[code]<?php
$dob = MakeSafe($_POST['dobd']) . '/' . MakeSafe($_POST['dobm']) . '/' . MakeSafe($_POST['doby']);
?>[/code]

Ken

Share this post


Link to post
Share on other sites
okay fine how about i one up you then!

if the only posted variables you have are those 3, then all you have to do is this:

$dob = implode('/',$_POST);

oh snap! ;D

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.