tags:

views:

67

answers:

1

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

The first one has <p> and </p> at the beginning and at the end. In the second one, all img tag has <p> and </p> tags.

UPDATE

 <p><span>Homepage</span><img src="../../assets/images/prints/print2_600x300.gif" alt="" width="600" height="300">
<span>Content Page</span><img src="../../../assets/images/support_images/imageA_600x300.gif" alt="" width="600" height="300">
<span>Dropdown Menu</span><img src="../../../assets/images/support_images/imageB_600x300.gif" alt="" width="600" height="300">
<span>Comments List</span><img src="../../../assets/images/support_images/imageC_600x300.gif" alt="" width="600" height="300">
<span>Comment Form</span><img src="../../../assets/images/support_images/imageD_600x300.gif" alt="" width="600" height="300"></p>

or

<p><span>Homepage</span></p>     
<p><img src="../../assets/images/prints/print2_600x300.gif" alt="" width="600" height="300"></p>
<p><span>Content Page</span></p>  
<p><img src="../../../assets/images/support_images/imageA_600x300.gif" alt="" 
width="600" height="300">
<p><span>Dropdown Menu</span></p>
<p><img src="../../../assets/images/support_images/imageB_600x300.gif" alt="" width="600" height="300"></p>
<p><span>Comments List</span></p>
<p><img src="../../../assets/images/support_images/imageC_600x300.gif" alt="" width="600" height="300"></p>
<p><span>Comment Form</span></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><img alt="" src="assets/images/prints/print2_600x300.gif" /></li> 
<li><span>Content Page</span><img alt="" src="assets/images/support_images/imageA_600x300.gif" /></li> 
<li><span>Dropdown Menu</span><img alt="" src="assets/images/support_images/imageB_600x300.gif" /></li> 
<li><span>Comments List</span><img alt="" src="assets/images/support_images/imageC_600x300.gif" /></li> 
<li><span>Comment Form</span><img alt="" src="assets/images/support_images/imageD_600x300.gif" /></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] => <p><img src="../../assets/images/prints/print2_600x300.gif" alt="" width="600" height="300">Homepage<img src="../../../assets/images/support_images/imageA_600x300.gif" alt="" width="600" height="300">Content Page<img src="../../../assets/images/support_images/imageB_600x300.gif" alt="" width="600" height="300">Dropdown Menu<img src="../../../assets/images/support_images/imageC_600x300.gif" alt="" width="600" height="300">Comment List<img src="../../../assets/images/support_images/imageD_600x300.gif" alt="" width="600" height="300">Comment Form</p>
        [product_order] => 0
        [class] =>
        [grouping] =>
        [status] => active
        [category_id] => 5
        [featured] => front
        [other_feature] => none
        [price] => 0.00
    )
A: 

Expect for very simple tasks, it won't be easy to do what you want with regex.

You can use an XML parser like SAX or DOM.

You can also take a look to these two library :

Boris Guéry
The PHP DOMDocument reads invalid HTML too, up to a certain extent. Everything else can be passed through tidy first to make absolutely sure.
Tomalak
Ok, I though it won't, thank you !
Boris Guéry
http://php.net/manual/en/domdocument.loadhtml.php - quote: "Unlike loading XML, HTML does not have to be well-formed to load."
Tomalak