在回显内容时插入span或li标记


insert span or li tag while echo ing the content

我需要在内容的每个换行符之后插入span标记,同时返回。

我怎样才能做到这一点?

我知道nl2br(string)它插入符合XHTML。

 The nl2br() function inserts HTML line breaks (<br />) in front of
   each newline ('n) in a string.
  • 如何在我的内容中使用echo或显示我的
    时获得<span>标签每个换行后的内容…
  • 我还需要在我的内容中插入<li>标签,同时显示数据使用回声

任何想法。这是一个简单的要求,但我不明白知道怎么解吗?

任何帮助都非常感谢。

许多谢谢。

我不明白为什么响应"<span>"不会为您工作,但您总是可以在php代码中编写html。例如:

foreach($result in $results)
{
?>
    <a>
<?php
    echo $result["column"];
?>
    </a>
<?php
}

我找到了这个…我正在寻找像这样的span作为预定义函数是不可用的echo…

    function nl2p($string, $line_breaks = true, $xml = true)
{
    // Remove existing HTML formatting to avoid double-wrapping things
    $string = str_replace(array('<p>', '</p>', '<br>', '<br />'), '', $string);
    // It is conceivable that people might still want single line-breaks
    // without breaking into a new paragraph.
    if ($line_breaks == true)
        return '<p>'.preg_replace(array("/(['n]{2,})/i", "/([^>])'n([^<])/i"), array("</p>'n<p>", '<br'.($xml == true ? ' /' : '').'>'), trim($string)).'</p>';
    else 
        return '<p>'.preg_replace("/(['n]{1,})/i", "</p>'n<p>", trim($string)).'</p>';
}  

    <?php
$text = "Hello.
My name is Geoffrey.";
echo nl2p($text);
?>

谢谢大家