PHP - 将段落转换为项目符号

时间:2015-01-07 04:53:15

标签: php

我正在编写一个小代码,我希望将整个段落转换为项目符号。所以基本上,在每.个新子弹开始之后。这在PHP中有多冷?

4 个答案:

答案 0 :(得分:2)

尝试这样:使用explode创建所有可能的数组,然后您可以使用array_filter删除空值。

<?php 
$str="hi.hello.how.";
$arr=explode('.',$str);
echo "<ul><li>" . implode("</li><li>", array_filter($arr)) . "</li></ul>"

?>

答案 1 :(得分:1)

因为这是一个通用的问题,要求#34;为我做这件事,这就是我要告诉你的全部内容。你必须弄清楚其余部分。

$elements = explode(".", $string);

echo "<ul><li>" . implode("</li><li>", $elements) . "</li></ul>"

答案 2 :(得分:1)

$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>";

答案 3 :(得分:1)

您可以使用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>';

?>