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

时间:2016-12-19 22:07:10

标签: php

我正在使用Google NL处理器API中的代码:

events.js:160
      throw er; // Unhandled 'error' event
      ^
Error: **The partial _common/header/header could not be found**
    at Object.invokePartial (C:\wamp\www\developer\HTML_seed\node_module
s\handlebars\dist\cjs\handlebars\runtime.js:271:11)
    at Object.invokePartialWrapper [as invokePartial] (C:\wamp\www\devel
oper\HTML_seed\node_modules\handlebars\dist\cjs\handlebars\runtime.js:68:39)
    at Object.eval (eval at createFunctionContext (C:\wamp\www\developer
\HTML_seed\node_modules\handlebars\dist\cjs\handlebars\compiler\javascript-compi
ler.js:254:23), <anonymous>:5:31)
    at main (C:\wamp\www\developer\HTML_seed\node_modules\handlebars\dis
t\cjs\handlebars\runtime.js:173:32)
    at ret (C:\wamp\www\developer\HTML_seed\node_modules\handlebars\dist
\cjs\handlebars\runtime.js:176:12)
    at ret (C:\wamp\www\developer\HTML_seed\node_modules\handlebars\dist
\cjs\handlebars\compiler\compiler.js:525:21)
    at DestroyableTransform._transform (C:\wamp\www\developer\HTML_seed\
node_modules\gulp-compile-handlebars\index.js:131:31)
    at DestroyableTransform.Transform._read (C:\wamp\www\developer\HTML_
seed\node_modules\gulp-compile-handlebars\node_modules\readable-stream\lib\_stre
am_transform.js:184:10)
    at DestroyableTransform.Transform._write (C:\wamp\www\developer\HTML
_seed\node_modules\gulp-compile-handlebars\node_modules\readable-stream\lib\_str
eam_transform.js:172:12)
    at doWrite (C:\wamp\www\developer\HTML_seed\node_modules\gulp-compil
e-handlebars\node_modules\readable-stream\lib\_stream_writable.js:237:10)

无论我放入什么文本,一切都运行正常。但是,API能够分别分析每个单独的文本行(您可以在此处尝试:https://cloud.google.com/natural-language/)。如果你输入两个不同的行,那么你会得到每个行的情绪。

我想重新创建它,但无论我如何尝试包含换行符(使用此处的所有方法:Writing TXT File with PHP, Want to Add an Actual Line Break),它都被分析为一个大文本块。

Google表示内容以下列格式发送(如果这有帮助):

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;

0 个答案:

没有答案
相关问题