如何将文本转换为HTML?

时间:2014-08-30 07:37:01

标签: php html

我想做一些事情,比如将文本转换为html

简单的文字就像这样

   "Vehicle Title Not Required/Not Issued 

•1962 and older year model vehicles 
•Agricultural, horticultural or livestock raising equipment or vehicles that are not required to be registered 
•Airplanes, aircraft 
•All terrain vehicles, off-road vehicles 
•Boat trailers 
•Boats, watercraft" 

我想将其转换为此

<p><span>"Vehicle Title Not Required/Not Issued&nbsp;</span><br /><br /><span>&bull;1962 and older year model vehicles&nbsp;</span><br /><span>&bull;Agricultural, horticultural or livestock raising equipment or vehicles that are not required to be registered&nbsp;</span><br /><span>&bull;Airplanes, aircraft&nbsp;</span><br /><span>&bull;All terrain vehicles, off-road vehicles&nbsp;</span><br /><span>&bull;Boat trailers&nbsp;</span><br /><span>&bull;Boats, watercraft"&nbsp;</span></p>

怎么做?

3 个答案:

答案 0 :(得分:1)

我假设您希望在PHP中执行此操作。

有几个PHP函数(如htmlencode和htmlentities)可以执行类似的操作。

我发现这个一致地工作:

mb_convert_encoding(htmlspecialchars($ string),'HTML-ENTITIES')

答案 1 :(得分:0)

简单:

<?php
  $input = " ... your text from above ...";
  echo "<p><span>";
  echo str_replace("\n", "</span><br /><br /><span>", $input);
  echo "</span></p>";
?>

答案 2 :(得分:0)

改用列表元素。

<p><span>&quot;Vehicle Title Not Required/Not Issued</span><br>
<ul>
<li>1962 and older year model vehicles</li>
<li>Agricultural, horticultural or livestock raising equipment or vehicles that are not required to be registered</li>
<li>Airplanes, aircraft </li>
<li>All terrain vehicles, off-road vehicles </li>
<li>Boat trailers </li>
<li>Boats, watercraft&quot;</li>
</ul>

PHP代码(您可能需要使用它):

<?php
echo "
<p><span>&quot;Vehicle Title Not Required/Not Issued</span><br>
<ul>
<li>1962 and older year model vehicles</li>
<li>Agricultural, horticultural or livestock raising equipment or vehicles that are not required to be registered</li>
<li>Airplanes, aircraft </li>
<li>All terrain vehicles, off-road vehicles </li>
<li>Boat trailers </li>
<li>Boats, watercraft&quot;</li>
</ul>
";
?>