为什么从一个字符串中删除多个空格

时间:2019-04-18 12:32:44

标签: javascript php

enter image description here

我有存储在数据库中的代码,并且在php中以html形式显示

我尝试了preg_replace,nl2br以及所有其他方法,但仍未获得预测的输出。

假设我有

这样的字符串

this is the test

$postContent = $getsingleviewodetail->epost_content;
$postContent = nl2br($postContent);
{!!substr($postContent,0,200)!!}

在测试前的上述句子中,我们有很多空格,我想在我的网页中显示这些空格。

enter image description here

3 个答案:

答案 0 :(得分:1)

执行以下操作:

strcmp
p {
  white-space: pre
}

答案 1 :(得分:0)

运行良好

在php

$string = "this is the                  test <br>test";
$string = preg_replace('#<br\s*/?>#', "\n", $string);

您认为

<pre>{{$string}}</pre>

enter image description here

答案 2 :(得分:-1)

<div class="dis_txt" style="white-space: pre;">
<a target="_blank" href="https://vdo.matrubharti.com/bites/hashtag/whythis">#whythis</a> <br>
<br>
why this is not working now                    -&gt; why this<br>
<br>
why this is not working n
<div id="video_content" class="collapse in" aria-expanded="true" style="">
                                ow                    -&gt; why this<br>
<br>
why this is not working now                    -&gt; why this<br>
<br>
why this is not working now                    -&gt; why this<br>
<br>
why this is not working now                    -&gt; why this<br>
why this is not working now                    -&gt; why this<br>
why this is not working now                    -&gt; why this<br>


   
   为什么现在不起作用->为什么这样