从变量而不是 ob_get_content 进行汇总

Summarize from a variable instead of ob_get_content

我有一个变量,其中包含一串文本和 p 标签,其中 p 标签表示不同的段落。我想从这个变量中得到的是创建一个摘要。我找到了一个看起来易于使用的库。但是我似乎无法让它与我的变量一起工作。它似乎只能使用 ob_get_content?

图书馆: https://github.com/freekrai/summarizer

到目前为止,我已经试过了,它似乎 return 不像演示中那样是摘要?

$full_text_strip = "<p>Counter-Strike: Global Offensive majors have a history of spurring serious roster overhauls. The moves following the results of ESL Katowice continue to reinforce tradition.</p><p>Penta Sports proved many doubters wrong by following up its first top-eight finish at a major at DreamHack Winter late last year with another top-eight finish at ESL Katowice. While the German squad did fall in the quarterfinal round to eventual champion Fnatic, the team proved without a doubt to be the best in Germany and among the best in Europe.</p>"

$st = new Summarizer();

$summary = $st->get_summary($full_text_strip);
echo $summary;
echo $st->how_we_did();

好吧,如果您做了演示中显示的内容,但无法正常工作,那么我建议您在他们的错误跟踪器中创建一个问题。但是对我来说,脚本有效。也许您应该首先检查您实际遇到的错误。比如你不关闭第一条语句,$full_text_strip...

的内容后面少了一个;
<?php

require 'summarizer.class.php';

$full_text_strip = "<p>Counter-Strike: Global Offensive majors have a history of spurring serious roster overhauls. The moves following the results of ESL Katowice continue to reinforce tradition.</p><p>Penta Sports proved many doubters wrong by following up its first top-eight finish at a major at DreamHack Winter late last year with another top-eight finish at ESL Katowice. While the German squad did fall in the quarterfinal round to eventual champion Fnatic, the team proved without a doubt to be the best in Germany and among the best in Europe.</p>";

$st = new Summarizer();

$summary = $st->get_summary($full_text_strip);
echo $summary;
echo $st->how_we_did();

以上内容符合我的预期。针对您的版本的修改:

  1. 字符串赋值后的尾随分号 (;),否则会出现语法错误和
  2. 需要 class 脚本

当您遇到 php 脚本问题时,总是 做的第一步是查看错误日志文件。那就是显示错误的地方。尝试 猜测 错误 可能 是什么是没有意义的,因为您所要做的就是阅读错误是什么。