Empty character exiting in Html

1

The page is:

link

The code is:

<?php
    require_once "../_controlls/_conexao/Conexao.php";
    require_once "../_controlls/_util/PhpUtil.php";     
    require_once "../_controlls/_models/Emails.php";
    require_once "../_controlls/_daos/EmailsDao.php";
    require_once "../_controlls/_util/Constantes.php";

    $connection = new Conexao(); 
    $conexao = $connection->abreConexao();
    $constantes = new Constantes();  
    $phpUtil = new PhpUtil();

    $_POST["assunto"] = 1;
    $_POST["nome"] = "Caca";
    $_POST["email"] = "[email protected]";
    $_POST["telefone"] = 3333333333;
    $_POST["descricao"] = "Teste";
    $_POST["qual"] = "";

    $assunto = $phpUtil->contatoTipos($_POST["assunto"]);   
    $emailsDao = new EmailsDao($conexao);

    $email = new Emails(
                     date("Y-m-d"), 
                     "n", 
                     $_POST["nome"], 
                     $_POST["email"], 
                     preg_replace( '#[^0-9]#', '', $_POST["telefone"] ),
                     $_POST["assunto"], 
                     $_POST["descricao"]);

    $emailsDao->cadastrar($email);

    $outro = $_POST["assunto"] == 6 ? "<b>Qual:</b> ".$_POST["qual"]."<br /><br />" : "";   

    $texto  = "<h2>".$constantes->getTituloSite()."</h2><br />";
    $texto .= "<img style='display:block; margin:0 auto;' src='".$constantes->getHttpSite()."/_img/logo.png' />";
    $texto .= "<b>Olá, você nos enviou um e-mail com a seguinte mensagem:</b><br /><br />";
    $texto .= "<b>Nome:</b> ".$_POST["nome"]."<br /><br />";
    $texto .= "<b>Telefone:</b> ".$_POST["telefone"]."<br /><br />";
    $texto .= "<b>E-mail:</b> ".$_POST["email"]."<br /><br />";
    $texto .= "<b>Interesse:</b> ".$assunto."<br /><br />";
    $texto .= $outro;
    $texto .= "<b>Descrição:</b><br />".nl2br($_POST["descricao"])."<br /><br /><br />";
    $texto .= "Estaremos respondendo o mais rápido possível<br /><br />";

    require_once "../_controlls/_models/EmailEnviar.php";
    require_once "../_controlls/_daos/EmailEnviarDao.php";

    $html = "<!doctype html>
             <html>
              <head>
                <meta charset='utf-8'>
                <title>".$constantes->getTituloSite()."/title>
              </head>           
              <body>".$texto."</body>
             </html>";

    $assuntoCodificado = sprintf('=?%s?%s?%s?=', 'UTF-8', 'Q', quoted_printable_encode("Re: ".$assunto));


    $emailEnviar = new EmailEnviar( 
          $_POST["nome"], 
          $_POST["email"],
          $constantes->getTituloSite(), 
          "[email protected]",
          $assuntoCodificado,
          $texto
    );

    $emailEnviarDao = new EmailEnviarDao();

    $enviarEmail = $emailEnviarDao->enviaEmail($emailEnviar);   

    if ($enviarEmail["success"] == 1) {

        var_dump ("OK");

    } else {

        var_dump ("ERRO");

    }

?>

When it works, html should retornar

"OK"

When wrong, html should retornar

"ERROR"

In fact this is happening. But with spaces in the beginning.

"OK" and "ERROR"

This is causing me problems at the time to get this result with JQuery AJax

This could be solved by giving trim in ajax but would like to understand where this space is coming from since none of the files involved has a BOM signature.

Output html not Ctrl+U

    
asked by anonymous 09.11.2016 / 15:51

4 answers

1

This extra space may only come from one of the require_once .

It checks all these files, and ensures that you have no space before <?php and if ?> exists in those files.

    
09.11.2016 / 17:21
0

Are you sure this is indeed happening?

Try to use var_dump to display "OK" and "ERROR" , this function returns in addition to the string the total number of characters it has. You might be getting confused by the fact that some browsers set a margin default to tag body

    
09.11.2016 / 16:04
0

In the output there is

[carriage return][space][space]string(2) "OK"[space]

The ASCII codes

[carriage return] 13
[space] 32

From the Google Chrome view-source, the carriage return does not break the line, giving the impression of being a space character. But if you copy and paste in a text editor you can see.

Some of these included files are probably dropping these characters. Review the codes of the following files:

../_controlls/_conexao/Conexao.php
../_controlls/_util/PhpUtil.php     
../_controlls/_models/Emails.php
../_controlls/_daos/EmailsDao.php
../_controlls/_util/Constantes.php
../_controlls/_models/EmailEnviar.php
../_controlls/_daos/EmailEnviarDao.php

Note that there is still an extra space after var_dump() , but it is not possible to determine by the code you have posted.

Probably the same situation, some other file even dropping characters without proper control, somewhere after var_dump() .

Be aware also that var_dump() inserts a line break at the beginning and end. Try to apply only a echo 'OK' , since var_dump() is normally used for debugging.

    
09.11.2016 / 17:48
0

Well, I did it with everyone's help!

Next: When you have JQuery .load or Ajax .load , these functions want to receive only the desired result .

When we do, for example, ?> and soon after we have spaces, line breaks and other things, then those details also go to result along with variables.

If you do not need to validate anything, then you will not have problems with the return. But if you need to make any comparisons, you'll need to first trim () to remove the unwanted characters if they exist.

    
09.11.2016 / 18:20