PHP - 将段落转换为要点
PHP - Converting paragraph into bullet points
我正在编写一个小代码,我想将整个段落转换为要点。所以基本上,在每 .
之后应该开始一个新的项目符号。这在PHP中如何实现?
由于这是 "do this for me" 的一般性问题,所以我将向您展示这一切。剩下的你就得想办法了。
$elements = explode(".", $string);
echo "<ul><li>" . implode("</li><li>", $elements) . "</li></ul>"
$paragraph = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
$lines = str_replace(".", "<li>", $paragraph);
echo "<ul>";
echo $lines;
echo "<ul>";
这样尝试:使用 explode
生成所有可能的数组,然后您可以使用 array_filter
删除空值。
<?php
$str="hi.hello.how.";
$arr=explode('.',$str);
echo "<ul><li>" . implode("</li><li>", array_filter($arr)) . "</li></ul>"
?>
可以使用PHP的分解功能。
http://php.net/manual/en/function.explode.php
这是一个示例代码:
<?php
$s = 'asdf. asdffff. asdfasfda.';
echo 's = ' . $s . '</br>';
$V = explode(".", $s);
echo '<ul>';
foreach($V as $x) {
echo '<li>' . $x . '</li>';
}
echo '</ul>';
?>
我正在编写一个小代码,我想将整个段落转换为要点。所以基本上,在每 .
之后应该开始一个新的项目符号。这在PHP中如何实现?
由于这是 "do this for me" 的一般性问题,所以我将向您展示这一切。剩下的你就得想办法了。
$elements = explode(".", $string);
echo "<ul><li>" . implode("</li><li>", $elements) . "</li></ul>"
$paragraph = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
$lines = str_replace(".", "<li>", $paragraph);
echo "<ul>";
echo $lines;
echo "<ul>";
这样尝试:使用 explode
生成所有可能的数组,然后您可以使用 array_filter
删除空值。
<?php
$str="hi.hello.how.";
$arr=explode('.',$str);
echo "<ul><li>" . implode("</li><li>", array_filter($arr)) . "</li></ul>"
?>
可以使用PHP的分解功能。
http://php.net/manual/en/function.explode.php
这是一个示例代码:
<?php
$s = 'asdf. asdffff. asdfasfda.';
echo 's = ' . $s . '</br>';
$V = explode(".", $s);
echo '<ul>';
foreach($V as $x) {
echo '<li>' . $x . '</li>';
}
echo '</ul>';
?>