【问题标题】:How to get the indented text from the Twitter API?如何从 Twitter API 获取缩进文本?
【发布时间】:2020-10-12 20:25:50
【问题描述】:

我正在使用以下 cURL 请求从一个帐户获取所有推文:

$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$requestMethod = 'GET';
$getfield = '?screen_name=heregoestheaccount&tweet_mode=extended&count=50';
$twitter = new TwitterAPIExchange($settings);
$twitter->setGetfield($getfield);
$twitter->buildOauth($url, $requestMethod);
$response = $twitter->performRequest(true, array(CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0));
$tweets = json_decode($response, true);

我现在得到以下数组:

array (size=26)
  'created_at' => string 'Fri Sep 25 12:05:51 +0000 2020' (length=30)
  'id' => int 1309464126494846976
  'id_str' => string '1309464126494846976' (length=19)
  'full_text' => string '[ #Esports ]

On Sunday 27.09.2020 at 1 p.m. the First Division Qualifier for the Rainbow Six: Siege Fall Season 2020 will start! Our team will fight for its slot in the first division.

We wish all the best for their first competition in the noetic team!

#noeticBLAST ???????? (length=302)
  'truncated' => boolean false
  'display_text_range' => 
    array (size=2)
      0 => int 0
      1 => int 272
  'entities' => 
...

我的问题是,在渲染推文的full_text 时,文本不遵循原始缩进,因为它是这样渲染的。

如何显示推文的原始缩进?

编辑:我有以下 HTML 来显示文本:

<div class="col-sm-12 col-md-7">
    <p>
        <?= $tweet['full_text']; ?>
    </p>
</div>

编辑2:根据@Pascal 评论,我在&lt;p&gt; 中添加了&lt;pre&gt; 标签。

显示的内容如下:

enter image description here

但这不是我想要的,因为我不希望用户必须滚动才能看到文本。

【问题讨论】:

  • 像这样&lt;pre&gt;...&lt;/pre&gt;把它放在pre tag html中并做一些css
  • 你能告诉我在编辑之后我应该把它放在哪个地方吗?
  • 在你的 p 标签里面,比如&lt;p&gt;&lt;pre&gt;&lt;?= $tweet['full_text']; ?&gt;&lt;/pre&gt;&lt;/p&gt;
  • 请检查我在帖子中添加的内容:)
  • 我知道你想要什么,为了完成任务,你应该创建自定义格式的文本来完成这项工作。这是一篇可能会引起兴趣的帖子stackoverflow.com/questions/11533214/…

标签: php twitter


【解决方案1】:

我发现了如何做到这一点。这很丑,但它有效:

<?=str_replace(array("\r\n", "\r", "\n"), "<br/>", $tweet['full_text']); ?></p>

【讨论】:

    猜你喜欢
    • 2014-05-23
    • 2016-03-05
    • 2013-06-14
    • 2014-07-07
    • 2016-06-21
    • 2018-06-27
    • 1970-01-01
    • 2019-08-10
    • 2012-12-12
    相关资源
    最近更新 更多