douxiang3978 2013-08-22 09:45
浏览 25
已采纳

联系表格:解析错误[关闭]

I can't see what's my mistake. I have to put some text. I have too much code? I'm little stressed by this problem. I'm a beginner and I'm working too hard perhaps.

<?php

    $n = array();

    if (!empty($_POST))
    {
        extract($_POST);
        $valid = true;

        if (empty($nom))
        {
            $valid = false;
            $erreur = 'Erreur nom';
            $n['erreurnom'] = true;
        }

        if (empty($email))
        {
            $valid = false;
            $erreur = 'Erreur email';
            $n['emailinvalide'] = false;
            $n['erreuremail'] = true;
        }
        elseif (!preg_match('/^[a-z0-9\-_.]+@[a-z0-9\-_.]+\.[a-z]{2,3}$/i', $email))
        {
            $valid = false;
            $erreur = 'Votre email n\'est pas valide';
            $n['erreuremail'] = false;
            $n['emailinvalide'] = true;
        }

        if (empty($message))
        {
            $valid = false;
            $erreur = 'Erreur message';
            $n['erreurmessage'] = true;
        }
    }
    else
    {
        $valid = false;
    }   
    $n['valide'] = $valid;
    echo json_encode($n);


    if ($valid = true)
    {
        $to = 'lalala@monmail.fr<script type="text/javascript">
    /* <![CDATA[ */
    (function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){})();
    /* ]]> */
    </script>';
        $sujet = $nom . ' a contacté le site';
        $header = 'From: $nom <$email> 
';
        $message = stripslashes($message);
        $nom = stripslashes($nom);

        if (mail($to, $sujet, $message, $header))
        {
            $erreur = 'Votre email nous est bien parvenu';
        }
        else
        {
            $erreur = 'Une erreur est survenue. Mail bloqué';
        }
        echo $erreur;
    }
?>

My problem: parse error in "(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script") ....."

  • 写回答

2条回答 默认 最新

  • doulai8405 2013-08-22 09:50
    关注
    '[...]previousSibling;a=l.getAttribute(('data-cfemail')[...]'
                                            ^            ^
                                            here         and here
    

    You use a ' in a string which was opened with ', you have to escape it to \', like that:

    '[...]previousSibling;a=l.getAttribute((\'data-cfemail\')[...]'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波