Php 用换行符在变量中存储文本

Php 用换行符在变量中存储文本,php,Php,我使用的代码来自Google NL处理器API: require __DIR__ . '/vendor/autoload.php'; use Google\Cloud\NaturalLanguage\NaturalLanguageClient; $projectId = 'YOUR_PROJECT_ID'; $language = new NaturalLanguageClient([ 'projectId' => $projectId ]); $text = 'Hello

我使用的代码来自Google NL处理器API:

require __DIR__ . '/vendor/autoload.php';

use Google\Cloud\NaturalLanguage\NaturalLanguageClient;

$projectId = 'YOUR_PROJECT_ID';

$language = new NaturalLanguageClient([
    'projectId' => $projectId
]);

$text = 'Hello, world!'; //THIS LINE IS THE ISSUE
# Detects the sentiment of the text
$annotation = $language->analyzeSentiment($text);
$sentiment = $annotation->sentiment();
echo 'Text: ' . $text . '
Sentiment: ' . $sentiment['score'] . ', ' . $sentiment['magnitude'];
return $sentiment;
无论我输入什么文本,一切都很好。但是,API能够单独分析每一行文本(您可以在此处尝试:)。如果你写了两行不同的话,你就会得到每一行的情感

我想重新创建它,但无论我如何尝试包含换行符(使用此处的所有方法:),它都将作为一个大文本块进行分析

谷歌表示,内容以以下格式发送(如果有帮助):


如何在文本中添加新行?了解API解释为新的内容也会有所帮助line@dan08是的,我试着把它们放在不同的行上,
\n
'\r\'
和其他几行。我看了所有的文档,但什么也找不到。
{
 "document":{
  "type":"PLAIN_TEXT",
  "language": "EN",
  "content":"'Lawrence of Arabia' is a highly rated film biography about \
            British Lieutenant T. E. Lawrence. Peter O'Toole plays \
            Lawrence in the film."
  },
  "encodingType":"UTF8"
}