Format buffer, php

1

I do not know if the right word is buffer but how do you make the JavaScript code "clean" like this:

({"content":"<div id=\"_sub-item\">Espere, ser\u00e1 exibido ap\u00f3s o carregamento dos itens.<\/div>"

Can you see that he has listed all "and coded ready to display to the browser?"

How do you do this with PHP?

    
asked by anonymous 13.10.2015 / 15:24

3 answers

2

The encoding returned in your example is part of the serialization generated by the json_encode function.

Example:

json_encode(array(
 'conteúdo' => '<div class="alguma-coisa">Alguma coisa e acentuação para testar</div>'
));

If you want to encode some string with escaped characters for HTML entities, you can use the htmlentities function.

echo htmlentities('"meu nome é wallace"');
    
13.10.2015 / 15:39
1

Use json_encode () to get the expected output:

<?php
$str = "<div>Espere, será exibido após o carregamento dos itens.</div>";
$json = json_encode($str);
print_r($json);

Output:

"<div>Espere, ser\u00e1 exibido ap\u00f3s o carregamento dos itens.<\/div>"
    
13.10.2015 / 15:38
1

This apparently seems to me to be a JSON output, in PHP you convert this output this way in PHP:

    $saida  = array(
                'content'=>'<div id="_sub-item">
                               Espere, será exibido após 
                               o carregamento dos itens.
                              </div>'
              );
   echo json_encode($saida);
    
13.10.2015 / 15:44