Search code examples
phplocalizationlocaletcpdfstrftime

php tcpdf not displaying accented characters from strftime


so I'm setting the locale with

setlocale(LC_TIME, "fr_FR");

and then using strftime like so

$membershipStartDate = strftime('%A le %e %B %G', strtotime($_POST['membershipStartDate']));

this is working but the spelling of August in french is wrong. It's outputting the %B as "aot" when it should be "août"

anybody have any ideas?

EDIT: it looks like it might be a problem with TCPDF. If I use the Write() method with accents in a string it works. But if I use the strftime() function those accents do not show up. Using strftime() outside of TCPDF works as well.

$pdf->Write(0,'août','',0,'L',false,0,false,true,0); // accents output correctly
$pdf->Write(0,$membershipStartDate,'',0,'L',false,0,false,true,0); // doesn't show accents

Solution

  • Wrapping strftime() in utf8_encode() solved it. Not sure if it's a bug with strftime() or TCPDF.

    $membershipStartDate = utf8_encode(strftime('%A le %e %B %G', strtotime($_POST['membershipStartDate'])));