我想做一些事情,比如将文本转换为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 </span><br /><br /><span>•1962 and older year model vehicles </span><br /><span>•Agricultural, horticultural or livestock raising equipment or vehicles that are not required to be registered </span><br /><span>•Airplanes, aircraft </span><br /><span>•All terrain vehicles, off-road vehicles </span><br /><span>•Boat trailers </span><br /><span>•Boats, watercraft" </span></p>
怎么做?
答案 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>"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"</li>
</ul>
PHP代码(您可能需要使用它):
<?php
echo "
<p><span>"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"</li>
</ul>
";
?>