我正在尝试添加列表。例如,如果我有这个:
Fits 10" - 24" TVs ;_ Holds up to 80lbs ;_ Mounts to a single wood stud, concrete or cinder block ;_ Low-profile design holds screen less than 1" from the wall ;_
问题1:如何<li>
在</li>
正则表达式的; _之前和之后添加
:
<ul>;_ <li>Fits 10" - 24" TVs</li>;_ <li>Holds up to 80lbs</li>;_ <li>Mounts to a single wood stud, concrete or cinder block</li>;_ <li>Low-profile design holds screen less than 1" from the wall</li>;_ </ul>'
而问题2:如何在<ul>
和</ul>
在列表中,如果可能的末尾或者(如果需要)。
使用方法如下:
$s = ".. ;_ ..";
$list = explode(';_', $s);
$html = "<ul><li>".implode('</li><li>', $list)."</li></ul>";
甚至:
echo "<ul><li>".implode('</li><li>', explode(';_', ".. ;_ .."))."</li></ul>";
看起来很普通;)
添加:
用伪代码,因为我不知道您使用的是什么数据库API。
if (!($q = $db->query("SELECT id, html FROM wp_table_name"))) {
throw new Exception("No rows returned");
}
$rows = array();
while ($row = $q->fetch_object()) {
$db->query("UPDATE wp_table_name SET html = ? WHERE id = ?", array(
"<ul><li>".implode('</li><li>', explode(';_', $row->html))."</li></ul>",
$row->id
));
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句