Jump to content

Implode count :ll


xyn

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]
Link to comment
https://forums.phpfreaks.com/topic/24874-implode-count-ll/
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
Link to comment
https://forums.phpfreaks.com/topic/24874-implode-count-ll/#findComment-113367
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]

Link to comment
https://forums.phpfreaks.com/topic/24874-implode-count-ll/#findComment-113370
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
Link to comment
https://forums.phpfreaks.com/topic/24874-implode-count-ll/#findComment-113375
Share on other sites

Archived

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

×
×
  • Create New...

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.