开发者

display string in PHP with preg_match

开发者 https://www.devze.com 2023-02-11 01:39 出处:网络
I got the following string: low|Low Resolution jpeg high|High Resolution jpeg eps|Eps I would like to display in like :

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

精彩评论

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