How to split Facebook birthday (mm/dd/aaaa) into 3 different values and assign them to 3 different fields (day, month, year)

StackOverflow https://stackoverflow.com/questions/20343471

Question

Maybe someone could help me with this.. I use Facebook registration plugin for a CMS site.

The Facebook string is mm/dd/aaaa (12/13/2014)

The problem is that when I try to replace the month number with the month name it doesn't work.

$user->birthdaymonth = substr($data['birthday'], 0, 2, str_replace(array('01', '02' , '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'), array('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre')));

This other two lines work perfectly:

$user->birthdayday = substr($data['birthday'], 3, 2);
$user->birthdayyear = substr($data['birthday'], 6, 4);

Thanks for your help!

Was it helpful?

Solution

That's the correct syntax-

$user->birthdaymonth = str_replace(array('01', '02' , '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'), array('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'), substr($data['birthday'], 0, 2));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top