使用explode()
, 然后从结果数组构建列表:
$str = "10:00|10:15|10:30";
$out = "";
foreach ( explode( "|", $str ) as $value ) {
$out .= "<li>{$value}</li>";
}
echo "<ul>{$out}</ul>";
结果是:
<ul>
<li>10:00</li>
<li>10:15</li>
<li>10:30</li>
</ul>
从这里添加您的输入是一件轻而易举的事:
foreach ( explode( "|", $str ) as $value ) {
$out .= "<li>
<input class='left' type='text' value='{$value}' />
<div class='del right'>x</div>
</li>";
}
留给您以下内容:
<ul>
<li>
<input class='left' type='text' value='10:00' />
<div class='del right'>x</div>
</li>
<li>
<input class='left' type='text' value='10:15' />
<div class='del right'>x</div>
</li>
<li>
<input class='left' type='text' value='10:30' />
<div class='del right'>x</div>
</li>
</ul>