1

I'm working with Mercado Livre API.

Since the user is allowed to use HTML in description field, I must allow it too. I'm using AJAX to communicate with Mercado Livre, but when I'm trying to parse a big HTML code, I'm not able to use json_decode on PHP.

How can I encode the user's HTML before sending it to PHP and decode it when it's received?

1
  • 1
    Please create a minimal example that reproduces the issue. Commented May 19, 2015 at 19:27

1 Answer 1

1

You first, require encode all HTML and next send this to API, for this, you can use the next function:

var encodedHtml = originalHtml.replace(/[\u00A0-\u9999<>\&]/gim, function(idx) {
  return '&#'+idx.charCodeAt(0)+';';
});

This code is on side client. To decode HTML in your server side, you need the use html_entity_decode PHP sentence.

I hope this help you.

Greetings

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.