How to convet a string to pieces with PHP or regex?

Posted by shin on Stack Overflow See other posts from Stack Overflow or by shin
Published on 2010-05-17T18:57:25Z Indexed on 2010/05/17 19:00 UTC
Read the original article Hit count: 163

Filed under:
|
|

I have different outputs of $slider['image']and two examples are followings.

The first one has

and

at the beginning and at the end. In the second one, all img tag has

and

tags.

 <p><img src="../../assets/images/prints/print2_600x300.gif" alt="" width="600" height="300"><img src="../../../assets/images/support_images/imageA_600x300.gif" alt="" width="600" height="300"><img src="../../../assets/images/support_images/imageB_600x300.gif" alt="" width="600" height="300"><img src="../../../assets/images/support_images/imageC_600x300.gif" alt="" width="600" height="300"><img src="../../../assets/images/support_images/imageD_600x300.gif" alt="" width="600" height="300"></p>

or

 <p><img src="../../assets/images/prints/print2_600x300.gif" alt="" width="600" height="300"></p><p><img src="../../../assets/images/support_images/imageA_600x300.gif" alt="" width="600" height="300"><img src="../../../assets/images/support_images/imageB_600x300.gif" alt="" width="600" height="300"></p><p><img src="../../../assets/images/support_images/imageC_600x300.gif" alt="" width="600" height="300"></p><p><img src="../../../assets/images/support_images/imageD_600x300.gif" alt="" width="600" height="300"></p>

I need to change this to the following.

<li><span>Homepage</span><a href="#"><img alt="" src="assets/images/prints/print2_600x300.gif" /></a></li> 
<li><span>Content Page</span><a href="#"><img alt="" src="assets/images/support_images/imageA_600x300.gif" /></a></li> 
<li><span>Dropdown Menu</span><a href="#"><img alt="" src="assets/images/support_images/imageB_600x300.gif" /></a></li> 
<li><span>Comments List</span><a href="#"><img alt="" src="assets/images/support_images/imageC_600x300.gif" /></a></li> 
<li><span>Comment Form</span><a href="#"><img alt="" src="assets/images/support_images/imageD_600x300.gif" /></a></li>

I assume I may need regex and php (explode, str_replace, foreach)for this but I need some help.

I appreciate your inputs and help.

Thanks in advance.

Full out put.

[0] =>; Array
    (
        [id] => 12
        [name] => Print 2
        [shortdesc] => <p>Print 2 short description</p>
        [longdesc] => <p>Print 2 long description</p>

        [thumbnail] => <p><img src="../../assets/images/prints/thumbnails/print2_223x112.gif" alt="" width="223" height="112"></p>
        [image] =&gt; <p><img src="../../assets/images/prints/print2_600x300.gif" alt="" width="600" height="300"><img src="../../../assets/images/support_images/imageA_600x300.gif" alt="" width="600" height="300"><img src="../../../assets/images/support_images/imageB_600x300.gif" alt="" width="600" height="300"><img src="../../../assets/images/support_images/imageC_600x300.gif" alt="" width="600" height="300"><img src="../../../assets/images/support_images/imageD_600x300.gif" alt="" width="600" height="300"></p>
        [product_order] => 0
        [class] =>
        [grouping] =>
        [status] => active
        [category_id] => 5
        [featured] => front
        [other_feature] => none
        [price] => 0.00
    )

© Stack Overflow or respective owner

Related posts about php

Related posts about regex