php - 如何从 Twitter API 获取缩进文本?
问题描述
我正在使用以下 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 评论,我<pre>
在我的<p>
.
这是显示的内容:
但这不是我想要的,因为我不希望用户必须滚动才能看到文本。
解决方案
我发现了如何做到这一点。这很丑陋,但它有效:
<?=str_replace(array("\r\n", "\r", "\n"), "<br/>", $tweet['full_text']); ?></p>
推荐阅读
- python - 在 Django 模板中仅显示正文的第一段
- python - Tensorflow: unable to share dense/kernel - ValueError: Trying to share variable dense/kernel, but specified shape (100, 160) and found shape (9, 100)
- d3.js - 中断 D3.js 中的滚动转换
- php - 将文本排除到有效数组
- solidity - 如何设置 require(msg.sender.balance >= msg.value)?
- dart - Flutter - DropdownButtonFormField 值未更新
- docker - 如何将 Docker 容器端口映射到不同的编号 - 但不在主机上
- css - 为什么高度在 IE11 上看起来如此不同?
- mongodb - 如何在具有整数键的嵌套数组中找到基于值的文档?
- javascript - 无法使用 pupette 从图像列表中获取 url