Empty character exiting HTML

Asked

Viewed 239 times

1

The page is:

http://www.hotplateprensas.com.br/_required/Email2.php

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 right, the html should retornar

"OK"

When it goes wrong, the html should retornar

"ERROR"

In fact this is happening. However, with spaces at the beginning.

" OK", and " ERROR"

This is causing me trouble at the time catch this result with JQuery AJax

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

Exit html in the Ctrl+U

inserir a descrição da imagem aqui

  • Check if there is an echo in any imported file, it does not seem to come from that file

  • I searched them all. None has echo. Since they are classes or function files only have Returns

  • 1

    Go echo '1'; echo '2'; echo '3'; and successively by the code you will see on which stretch the space is inserted. Much faster than breaking your head. Put the first one right after the <?php , after the require/includes etc. Where the space appears, you will surround.

4 answers

1

That extra space could only be coming from one of the require_once.

Check all those files, and make sure you have no space before the <?php and whether the termination ?> exists in those files.

  • I understood the problem. The detail was not ? > but what you have after it. You should have nothing. But still, a space appears after html

  • 2

    @Carlosrocha, if that answer helped you you can mark it as accepted

0

Are you sure this is actually happening?

Try to use the var_dump to show "OK" and "ERROR", this function returns beyond the string the total of characters it has. You may be confused due to the fact that some browsers define a margin standard for the tag body

  • In fact, the return of var_dump gives only 4 characters. But on the page, as Voce itself can check by the link I left in the question, has an empty character before the printing of the var_dump

  • I accessed the link, and that’s exactly what I said, there is this empty character, you may be getting confused with the margin as I quoted in the reply

  • I’m not confusing no. When I ask Jquery, it says it has more than 4 characters

  • Did you see Ctrl+U? You saw that before the html output there is a blank space?

  • Try removing the closing tag from php: ? > since your code does not have html the closing tag is not required

  • I edited the question and added an image showing what I am saying at the end of the question. Note the space before String and still has a line break after

  • removed the ? > and continued the problem

Show 2 more comments

0

On the way out there’s this

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

The ASCII codes

[carriage return] 13
[space] 32

From the Chrome view-source 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.

Probably some of these included files are 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 the var_dump(), but it is not possible to determine by the code you posted.

It’s probably the same situation, some other file included dropping characters without proper control, somewhere after the var_dump().

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

0

Well, I got it with everyone’s help!

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

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

If you don’t need to validate anything, then you won’t have a problem with the return. But if you need to make any comparison, you must first make a Trim() to remove unwanted characters if they exist.

Browser other questions tagged

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