display string in PHP with preg_match

263

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...

546

Answer

Solution:

Assuming you forgot a in your string:

<?php
$str = 'lowLow Resolution jpeghighHigh Resolution jpegepsEps';
foreach(array_chunk(explode('', $str), 2) as $chunk) {
    echo '<li>'.$chunk[0].'</li><span>'.$chunk[1]."</span>\n";
}
?>

People are also looking for solutions to the problem: timezone - PHP: Get Time for Current Region

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.