I would like to add a post in Wordpress with cURL (php) and I have this string to add as a content:

$text = "Trovato, assieme a Massimo e Anna, in una cantina di Via Barrili a Milano, con un'infezione agli occhi che ha provocato nei tre fratelli gradi diversi di cecità. Ci vede poco ed è molto timoroso. Con alcuni volontari ha creato un buon rapporto di fiducia. Ben inserito con gli altri gatti del reparto."

This is the conversion I make:

$content =  htmlspecialchars( $text, ENT_QUOTES|ENT_SUBSTITUTE );

The Post is created successfully but instead of è in the post I get a ? symbol inside a rhombus

WP Post Preview

Script on WP side:

error_reporting( E_ALL );

error_log("--- Received POST ---\r\n", 3, "./mqtest.log");
error_log(print_r($_POST,1), 3, "./mqtest.log");
error_log("\r\n", 3, "./mqtest.log");

$my_post = array(       
    //'post_type' => "post",    
    'post_content' =>  $_POST["content"],
    'post_title' => $_POST["name"]

try {

    $wp_error = "";
    error_log("Creating POST in Wordpress...\r\n", 3, "./mqtest.log");
    error_log(print_r($my_post,1), 3, "./mqtest.log");
    $post_id = wp_insert_post( $my_post );


any suggestion please?



htmlspecialchars() only converts &, ", ', < and >. To also convert (encode, really) accented characters, you need to use htmlentities(), and depending on the rest of your setup you may also have to specify which encoding to use. So:

$content =  htmlspecialchars( $text, ENT_QUOTES|ENT_SUBSTITUTE, 'UTF-8' );

(Substitute 'ISO-8859-1' for 'UTF-8' if necessary, though it probably won't be.)

  • Doesn't work, I tried both with UTF-8 and ISO-8859-1. – Sunchaser Oct 3 '17 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.