I have a WordPress plugin, which will gather post's information such as post title, post content and send to 3rd party application to do some analysis.
Basically will store post title and post content into array, encode the array into JSON format and send to 3rd party application via wp_remote_post
. I'm facing challenge in the post content which may containing some html tag and ruin my JSON data.
What should I do to prevent the post content breaking my JSON data? Should I sanitize it or in other way?
Example code as below:
$args = array(
'title' => get_the_title(),
'content' => get_the_content()
);
$json = json_encode($args);
wp_remote_post( 'http://dummydomain.com/', array(
'body' => array(
'data' => $args
)
) );