Information an HTML inside a JSON request in PHP

Asked

Viewed 206 times

0

I am developing an integration to send email inside Sendinblue, but in the request it is necessary to send the HTML code of the email and only works if I put " " in front of all double quotes.

I need to get the HTML that’s like this:

> <html xmlns="http://www.w3.org/1999/xhtml">
> <head> <meta http-equiv="Content-Type" content="text/html;
> charset=utf-8" /> <title>Email para Divulção de Produto</title>
> <style type="text/css"> .corpo1 { margin-left:auto;
> margin-right:auto; width:700px; height:auto; } .produtos {
> width:340px; height:405px; float:left; } .tituloproduto { font-family:
> Verdana, Geneva, sans-serif; font-size:14px; font-style:oblique; }
> .preheader { color:#c0c0c0; font-family: arial, helvetica, sans-serif;
> font-size: 12px; } </style> </head> <body> <div align="center">
> <!-- Tabela do Corpo do Email --> <table class="corpo1"
> width="95%" border="0" cellspacing="1"
> cellpadding="1"> <!-- Pre Header --> <tr align="center">
> <td class="preheader"> Ofertas para Acabar com os Estoques </td>

Exemplifying precise declare so:

> "<html xmlns=\\\"http://www.w3.org/1999/xhtml\\\">
> <head> <meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html;
> charset=utf-8\\\" /> <title>Email para Divulção de Produto</title>
> <style type=\\\"text/css\\\"> .corpo1 { margin-left:auto;
> margin-right:auto; width:700px; height:auto; } .produtos {
> width:340px; height:405px; float:left; } .tituloproduto { font-family:
> Verdana, Geneva, sans-serif; font-size:14px; font-style:oblique; }
> .preheader { color:#c0c0c0; font-family: arial, helvetica, sans-serif;
> font-size: 12px; } </style> </head> <body> <div align=\\\"center\\\">
> <!-- Tabela do Corpo do Email --> <table class=\\\"corpo1\\\"
> width=\\\"95%\\\" border=\\\"0\\\" cellspacing=\\\"1\\\"
> cellpadding=\\\"1\\\"> <!-- Pre Header --> <tr align=\\\"center\\\">
> <td class=\\\"preheader\\\"> Ofertas para Acabar com os Estoques </td>

I just took a piece of code to make it simple.

Is there a function within PHP that takes this HTML code and transforms it into JSON format?

Thank you,

  • How do I turn HTML into JSON? And what does that have to do with quotes escaping?

1 answer

0

In the context of PHP do:

$Dados = "<html xmlns=\\\"http://www.w3.org/1999/xhtml\\\">
<head> <meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html;
charset=utf-8\\\" /> <title>Email para Divulção de Produto</title>
<style type=\\\"text/css\\\"> .corpo1 { margin-left:auto;
margin-right:auto; width:700px; height:auto; } .produtos {
width:340px; height:405px; float:left; } .tituloproduto { font-family:
Verdana, Geneva, sans-serif; font-size:14px; font-style:oblique; }
.preheader { color:#c0c0c0; font-family: arial, helvetica, sans-serif;
font-size: 12px; } </style> </head> <body> <div align=\\\"center\\\">
<!-- Tabela do Corpo do Email --> <table class=\\\"corpo1\\\"
width=\\\"95%\\\" border=\\\"0\\\" cellspacing=\\\"1\\\"
cellpadding=\\\"1\\\"> <!-- Pre Header --> <tr align=\\\"center\\\">
<td class=\\\"preheader\\\"> Ofertas para Acabar com os Estoques </td>";
print json_eencode([
   "Dados" => $Dados
]);

In the context of JS receive:

$.get(URL, Params, function(Result) {
   $("TagHtmlRecebe").html(Result.Dados);
}, "HTML");
  • Cool, but I’m trying to make a post with CURL, I don’t use JS, I’ll try to add this in the context of PHP and test! thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.