如何从 Twitter API 获取缩进文本?
How to get the indented text from the 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 评论,我在 <p>
.
中添加了 <pre>
标签
显示的内容如下:
enter image description here
但这不是我想要的,因为我不希望用户必须滚动才能看到文本。
我知道怎么做了。它很丑陋,但它有效:
<?=str_replace(array("\r\n", "\r", "\n"), "<br/>", $tweet['full_text']); ?></p>
我正在使用以下 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 评论,我在 <p>
.
<pre>
标签
显示的内容如下:
enter image description here
但这不是我想要的,因为我不希望用户必须滚动才能看到文本。
我知道怎么做了。它很丑陋,但它有效:
<?=str_replace(array("\r\n", "\r", "\n"), "<br/>", $tweet['full_text']); ?></p>