如果我喜欢那个格式字符串,我怎样才能把它变成一个格式好的段落,用PHP作为例如CSS中的text-align:justify和浏览器窗口的全宽?
<?php
$text = "It is a long
established fact that a reader
will be distracted
by the readable content of a
page when looking at its layout.
The point of using Lorem Ipsum
is that it has a
more-or-less normal distribution of
letters, as opposed to using 'Content here,
content here', making it look like readable English.
Many desktop publishing packages and web
page editors now use Lorem Ipsum as their
default model text, and a search for 'lorem ipsum'
will uncover many web sites still in their infancy.
Various versions have evolved over the years,
sometimes by accident, sometimes on
purpose (injected humour and the like).
";
?>
结果我想将此段落改为以下格式:
一个长期存在的事实是,在查看其布局时,读者会被页面的可读内容分散注意力。使用Lorem Ipsum的关键在于它具有或多或少的正常字母分布,而不是在此处使用“内容”,这里的内容使其看起来像可读的英语。许多桌面出版包和网页编辑器现在使用Lorem Ipsum作为其默认模型文本,并搜索“lorem ipsum&#39;将发现仍处于起步阶段的许多网站。多年来,各种版本都有所发展,有时是偶然的,有时是故意的(注入幽默等)。
答案 0 :(得分:1)
此外,您在将它们分配给$ text对象时看到的所有换行符都不会被PHP保留。在存储文本字符串时,必须明确声明需要新行。
答案 1 :(得分:0)
将您的变量包装在<p>
标记中并应用样式
<?php
$text = "It is a long
established fact that a reader
will be distracted
by the readable content of a
page when looking at its layout.
The point of using Lorem Ipsum
is that it has a
more-or-less normal distribution of
letters, as opposed to using 'Content here,
content here', making it look like readable English.
Many desktop publishing packages and web
page editors now use Lorem Ipsum as their
default model text, and a search for 'lorem ipsum'
will uncover many web sites still in their infancy.
Various versions have evolved over the years,
sometimes by accident, sometimes on
purpose (injected humour and the like).
";
$text = "<p style='text-align:justify'>$text</p>";
echo $text;
<p style='text-align:justify'>It is a long
established fact that a reader
will be distracted
by the readable content of a
page when looking at its layout.
The point of using Lorem Ipsum
is that it has a
more-or-less normal distribution of
letters, as opposed to using 'Content here,
content here', making it look like readable English.
Many desktop publishing packages and web
page editors now use Lorem Ipsum as their
default model text, and a search for 'lorem ipsum'
will uncover many web sites still in their infancy.
Various versions have evolved over the years,
sometimes by accident, sometimes on
purpose (injected humour and the like).
</p>
&#13;
答案 2 :(得分:0)
您可以将段落存储为这样的字符串,并使用RegExp删除所有试验空白。
$ text = preg_replace('/ \ s + /','',$ text);