fork(12) download
  1. <?php
  2. $string = 'My long <a href="http://e...content-available-to-author-only...e.com/abc" rel="link">string</a> has any
  3. <a href="/local/path" title="with attributes">number</a> of
  4. <a href="#anchor" data-attr="lots">links</a>. ';
  5. $regex='|<a\s*href="([^"]+)"[^>]+>([^<]+)</a>|';
  6. $howmany = preg_match_all($regex,$string,$res,PREG_SET_ORDER);
  7. print_r($res);
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [0] => <a href="http://e...content-available-to-author-only...e.com/abc" rel="link">string</a>
            [1] => http://e...content-available-to-author-only...e.com/abc
            [2] => string
        )

    [1] => Array
        (
            [0] => <a href="/local/path" title="with attributes">number</a>
            [1] => /local/path
            [2] => number
        )

    [2] => Array
        (
            [0] => <a href="#anchor" data-attr="lots">links</a>
            [1] => #anchor
            [2] => links
        )

)