"Syntax error, unexpected 'if' (T_IF)", even without apparent error

3

You're giving this error:

  

Parse error: syntax error, unexpected 'if' (T_IF) in C: \ Program Files \ EasyPHP-Devserver-17 \ eds-www \ Hugg \ sys \ historico.php on line 3

I've been looking for the solution for some time but I can not find it. The error is in this line:

if(isset($_POST['mensagem'])){

The code:

header("Content-Type: application/json;charset=utf-8");
    if(isset($_POST['mensagem'])){
        include_once "../defines.php";
        require_once('../classes/BD.class.php');
        BD::conn();

        $mensagens = array();
        $id_conversa = (int)$_POST['conversacom'];
        $online = (int)$_POST['online'];

        $pegaConversas = BD::conn()->prepare("SELECT * FROM 'mensagens' WHERE ('id_de' = ? AND 'id_para' = ?) OR ('id_de' = ? AND 'id_para' = ?) ORDER BY 'id' DESC LIMIT 10");
        $pegaConversas->execute(array($online, $id_conversa, $id_conversa, $online));

        while($row = $pegaConversas->fetch()){
            $fotoUser = '';
            if($online == $row['id_de']){
                $janela_de = $row['id_para'];

            }elseif($online == $row['id_para']){
                $janela_de = $row['id_de'];

                $pegaFoto = BD::conn()->prepare("SELECT 'foto' FROM 'usuarios' WHERE 'id' = '".$row['id_de']."'");
                $pegaFoto->execute();

                while ($usr = $pegaFoto->fetch()){
                    $fotoUser = ($usr['foto'] == '') ? 'default.jpg' : $usr['foto'];
                }
            }

            $emotions = array(':P', ':$', ':|', ':O', '<3', ';*', ':%', ':@', ':D', ';D', ':A', ':"(', ':(', ':Z');
            $imgs = array(
                '<img src="smiles/tongue.png" width="16" height="16" border="0"/>',
                '<img src="smiles/redface.png" width="16" height="16" border="0"/>',
                '<img src="smiles/nada.png" width="16" height="16" border="0"/>',
                '<img src="smiles/espanto.png" width="16" height="16" border="0"/>',
                '<img src="smiles/blowkiss.png" width="16" height="16" border="0"/>',
                '<img src="smiles/kiss.png" width="16" height="16" border="0"/>',
                '<img src="smiles/zangado.png" width="16" height="16" border="0"/>',
                '<img src="smiles/mad.png" width="16" height="16" border="0"/>',
                '<img src="smiles/rindo.png" width="16" height="16" border="0"/>',
                '<img src="smiles/rindo2.png" width="16" height="16" border="0"/>',
                '<img src="smiles/anjo.png" width="16" height="16" border="0"/>',
                '<img src="smiles/choro.png" width="16" height="16" border="0"/>',
                '<img src="smiles/triste.png" width="16" height="16" border="0"/>',
                '<img src="smiles/dormindo.png" width="16" height="16" border="0"/>'
            );
            $msg = str_replace($emotions, $imgs, $row['mensagem']);
            $mensagens[] = array(
                'id' => $row['id'],
                'mensagem' => utf8_encode($msg),
                'fotoUser' => $fotoUser,
                'id_de' => $row['id_de'],
                'id_para' => $row['id_para'],
                'janela_de' => $janela_de
            );
        }
        die(json_encode($mensagens));
    }

I put it full here .

    
asked by anonymous 16.04.2018 / 05:57

1 answer

6

Almost every code editor has an option to show spaces and line breaks, if you enable the option in your editor during editing (at least when this type of problem arises), you'll probably find these things easier.

You can see by copying from your Pastebin and pasting into a code editor that you have a special invisible (null) character at the end of the line of the header.

<?php
header("Content-Type: application/json;charset=utf-8");
                                                       ^^ --- AQUI
    if(isset($_POST['mensagem'])){
        include_once "../defines.

View the file opened in a hexadecimal viewer:

I'veusedthisgreatfreetool: link


One of the simplest solutions for your case is to place the cursor before the ; , delete until you join the two lines thus:

header("Content-Type: application/json;charset=utf-8")f(isset($_POST['mensagem'])){
               É pra deletar até colar tudo mesmo ---^^ 

(this is to make sure you deleted the invisible characters).

Once this is done, enter ENTER between the lines again, reset the ; on the top line and the i on the if that the problem should be remedied. >     

16.04.2018 / 10:47