Php 源代码如何管理空白和连接

Php 源代码如何管理空白和连接,php,whitespace,double-quotes,linefeed,Php,Whitespace,Double Quotes,Linefeed,在以下代码中: $email_body = "message from $name \n" "email address $visitor_email \n" "\n $message"; 第四行由于意外的“”而生成解析错误,但引号似乎正确配对。那么为什么最后一行中的(最后一行?)引号是“意外的” 我希望$email_body的结果是: message from $name email address $visitor_em

在以下代码中:

    $email_body = 
       "message from $name \n" 
       "email address $visitor_email \n"
       "\n $message";
第四行由于意外的
”而生成解析错误,但引号似乎正确配对。那么为什么最后一行中的(最后一行?)引号是“意外的”

我希望$email_body的结果是:

    message from $name
    email address $visitor_email 

    $message

我已经浏览了php.net/manual上的语法页面,并阅读了这里的单引号和双引号问题。我找不到字符串开头换行符的任何异常,但它似乎就是这样。有人能澄清一下吗?

当我运行它时,错误在第三行,而不是第四行

这里的问题是,在另一个字符串文本旁边有一个字符串文本,它们之间没有运算符

这是错误的:

"foo" "foo" 
原样:

"foo"
"foo"
你可以这样做:

"foo" . "foo"


除非您使用
将字符串重新连接在一起,否则不要像那样拆分字符串

因此,要么:

 $email_body = 
   "message from $name \n 
   email address $visitor_email \n
   \n $message"; // also the whole string on one line is fine

你的错误是

第5行出错:分析错误,意外 T\u常量\u封装的\u字符串(“电子邮件地址$visitor\u电子邮件\n”

这就是你的错误开始的地方

$email_body = 
       "message from $name \n" // This line you need to add concatination
       "email address $visitor_email \n"
那么您的代码将如下所示

 <?php

 $email_body = 
       "message from $name \n". 
       "email address $visitor_email \n".
       "\n $message";

$email_body = 
       "message from $name \n" // This line you need to add concatination
       "email address $visitor_email \n"
 <?php

 $email_body = 
       "message from $name \n". 
       "email address $visitor_email \n".
       "\n $message";