Giving a follow up it this post: How to extract img src, title and alt from html using php?
I would like to format the array, I have this example:
$articletxt = 'Hello! this is my picture <format type="table" name="My Picture" data="http://www.example.com/myimage.jpg" caption="I look tired" /> But I look better in real life <br><br> Hello! this is my picture <format type="youtube" name="Unlock Samsung S5310 Galaxy Pocket Neo by USB" data="piHMEZlAAmA" /> But I look better in real life';
preg_match_all('/<format[^>]+>/i',$articletxt, $formatbusquedas); 
$img = array();
foreach( $formatbusquedas[0] as $img_tag) {
    preg_match_all('/(type|name|data)=("[^"]*")/i',$img_tag, $img[$img_tag]);
}
echo '<pre>';
print_r($img);
It will print out this:
Array
(
    [<format tipo="table" name="My Picture" data="http://www.example.com/myimage.jpg" caption="I look tired" />] => Array
        (
            [0] => Array
                (
                    [0] => tipo="table"
                    [1] => name="My Picture"
                    [2] => data="http://www.example.com/myimage.jpg"
                )
            [1] => Array
                (
                    [0] => tipo
                    [1] => name
                    [2] => data
                )
            [2] => Array
                (
                    [0] => "table"
                    [1] => "My Picture"
                    [2] => "http://www.example.com/myimage.jpg"
                )
        )
    [<format tipo="youtube" name="Unlock Samsung S5310 Galaxy Pocket Neo by USB" data="piHMEZlAAmA" />] => Array
        (
            [0] => Array
                (
                    [0] => tipo="youtube"
                    [1] => name="Unlock Samsung S5310 Galaxy Pocket Neo by USB"
                    [2] => data="piHMEZlAAmA"
                )
            [1] => Array
                (
                    [0] => tipo
                    [1] => name
                    [2] => data
                )
            [2] => Array
                (
                    [0] => "youtube"
                    [1] => "Unlock Samsung S5310 Galaxy Pocket Neo by USB"
                    [2] => "piHMEZlAAmA"
                )
        )
)
But I need it like this:
Array
(
    [<format tipo="table" name="My Picture" data="http://www.example.com/myimage.jpg" caption="I look tired" />] => Array
        (
            [tipo] => table
            [name] => My Picture
            [data] => http://www.example.com/myimage.jpg
        )
    [<format tipo="youtube" name="Unlock Samsung S5310 Galaxy Pocket Neo by USB" data="piHMEZlAAmA" />] => Array
        (
            [tipo] => youtube
            [name] => Unlock Samsung S5310 Galaxy Pocket Neo by USB
            [data] => piHMEZlAAmA
        )
)
How can this be made?
 
     
    