extracting source url and the anchor text in a string
<p>I am trying to extract data from a series of string but no luck.
in the example code below, I tried using preg_split but its not giving me the result I want.</p>

<p>using the code below:</p>

<pre><code>&lt;?php
$str = '&lt;a href="http://rads.stackoverflow.com/amzn/click/B008EYEYBA"&gt;Nike Air Jordan SC-2 Mens Basketball Shoes 454050-035&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=mytwitterpage-20&amp;l=as2&amp;o=1&amp;a=B008EYEYBA" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt;
';
$chars = preg_split('/ /', $str, -1, PREG_SPLIT_OFFSET_CAPTURE);

echo '&lt;pre&gt;';
print_r($chars);
echo '&lt;pre&gt;';
?&gt;
</code></pre>

<p>gives the result:</p>

<pre><code>Array
(
    [0] =&gt; Array
        (
            [0] =&gt;  0
        )

    [1] =&gt; Array
        (
            [0] =&gt; href="http://rads.stackoverflow.com/amzn/click/B008EYEYBA"&gt;Nike
            [1] =&gt; 3
        )

    [2] =&gt; Array
        (
            [0] =&gt; Air
            [1] =&gt; 167
        )

    [3] =&gt; Array
        (
            [0] =&gt; Jordan
            [1] =&gt; 171
        )

    [4] =&gt; Array
        (
            [0] =&gt; SC-2
            [1] =&gt; 178
        )

    [5] =&gt; Array
        (
            [0] =&gt; Mens
            [1] =&gt; 183
        )

    [6] =&gt; Array
        (
            [0] =&gt; Basketball
            [1] =&gt; 188
        )

    [7] =&gt; Array
        (
            [0] =&gt; Shoes
            [1] =&gt; 199
        )

    [8] =&gt; Array
        (
            [0] =&gt; 454050-035 205
        )

    [9] =&gt; Array
        (
            [0] =&gt; src="http://www.assoc-amazon.com/e/ir?t=mytwitterpage-20&amp;l=as2&amp;o=1&amp;a=B008EYEYBA"
            [1] =&gt; 224
        )

    [10] =&gt; Array
        (
            [0] =&gt; width="1"
            [1] =&gt; 305
        )

    [11] =&gt; Array
        (
            [0] =&gt; height="1"
            [1] =&gt; 315
        )

    [12] =&gt; Array
        (
            [0] =&gt; border="0"
            [1] =&gt; 326
        )

    [13] =&gt; Array
        (
            [0] =&gt; alt=""
            [1] =&gt; 337
        )

    [14] =&gt; Array
        (
            [0] =&gt; style="border:none
            [1] =&gt; 344
        )

    [15] =&gt; Array
        (
            [0] =&gt; !important;
            [1] =&gt; 363
        )

    [16] =&gt; Array
        (
            [0] =&gt; margin:0px
            [1] =&gt; 375
        )

    [17] =&gt; Array
        (
            [0] =&gt; !important;"
            [1] =&gt; 386
        )

    [18] =&gt; Array
        (
            [0] =&gt; /&gt;

            [1] =&gt; 399
        )

)
</code></pre>

<p>note in array1, the word "Nike is included when I only need is just the URL.</p>

<pre><code>[1] =&gt; Array
        (
            [0] =&gt; href="http://rads.stackoverflow.com/amzn/click/B008EYEYBA"&gt;Nike
            [1] =&gt; 3
        )
</code></pre>

<p>actually, my ultimate goal in extracting $str is just to output the source URL and the achor text in a separate array like so:</p>

<p><strong>URL:</strong></p>

<p><a href="http://rads.stackoverflow.com/amzn/click/B008EYEYBA" rel="nofollow">http://www.amazon.com/gp/product/B008EYEYBA/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B008EYEYBA&amp;linkCode=as2&amp;tag=mytwitterpage-20</a></p>

<p><strong>anchor text:</strong></p>

<p>Nike Air Jordan SC-2 Mens Basketball Shoes 454050-035</p>

<p>any idea how I can accomplish this is greatly appreciated.</p>
