开发者

display string in PHP with preg_match

I got the following string:

low|Low Resolution jpeg high|High Resolution jpeg eps|Eps

I would like to display in like :

<li>low</li><span>Low Resolution jpeg</span>
<li>high</li><span>High Resolution jpeg</span>
<li>eps</li><span>eps</span>

NB: The words 开发者_运维百科cn be changed in the string, how can I use something like pregmacthe...


Assuming you forgot a | in your string:

<?php
$str = 'low|Low Resolution jpeg|high|High Resolution jpeg|eps|Eps';
foreach(array_chunk(explode('|', $str), 2) as $chunk) {
    echo '<li>'.$chunk[0].'</li><span>'.$chunk[1]."</span>\n";
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜