Special characters in post_title replaced by ‘?’

Question

This is my code :

if( !empty( $_POST ) && !empty( $_POST['foo-action'] ) ){
    $html .= sprintf( '<table><thead><tr><th>%1$s</th><th>%2$s</th><th>%3$s</th></tr></thead><tbody>',
       'Post title',
       'pdf to import',
       'imported'
    );
    if( $_POST['foo-action'] === "newsletters" ){
        $category = get_category_by_slug( 'newsletters' );
        $atts = [
            'category' => $category->term_id,
            'posts_per_page' => -1,
            'order' => 'ASC'
        ];
        $newsletter_posts = get_posts( $atts );

        foreach ( $newsletter_posts as $newsletter_post ){
            $post_meta_data = get_post_meta( $newsletter_post->ID );
            $pdf = get_post( $post_meta_data['pdf'][0] );
            $html .= sprintf( '<tr><td>%1$s</td><td>%2$s</td><td>%3$s</td></tr>',
                $newsletter_post->post_title,
                $pdf->guid,
                'true'
            );
        }
    }
    $html .= sprintf( '</tbody></table>');
}

When the post title contains special characters like :

Foo n° 46 — 21 05 2014

The output displayed with $newsletter_post->post_title is :

Foo n° 46 ? 21 05 2014

How can I fixe this ?

0
J.BizMai 4 months 0 Answers 13 views 0

Leave an answer