Method 1
The code is as follows: |
Copy code |
$ A = '<a href = "www.111cn.net"> Baidu </a> gu ge <a href = "www.111cn.net"> Google </a> <a href = "www.111cn.net"> Yahoo </a> '; Preg_match_all ('/<a [^>] +> [^>] + a>/', $ a, $ aout ); Print_r ($ aout ); Result Array ( [0] => Array ( [0] => <a href = "www.111cn.net"> Baidu </a> [1] => <a href = "www.111cn.net"> Google </a> [2] => <a href = "www.111cn.net"> Yahoo </a> ) ) |
Method 2
Example:
The code is as follows: |
Copy code |
$ Str1 = '<a href = http://www.111cn.net> test </a> '; $ Str2 = '<a href = 'http: // www.111cn.net'> test </a> '; $ Str3 = '<a href = "export cnames: href ('test');" target = "_ blank"/> test </a> '; $ Regex = '/hrefs * = s *(? : "([^"] *) "| '([^'] *) '| ([^"'> S] + ))/'; Preg_match ($ regex, $ str1, $ matches ); Print_r ($ matches ); Preg_match ($ regex, $ str2, $ matches ); Print_r ($ matches ); Preg_match ($ regex, $ str3, $ matches ); Print_r ($ matches ); Matching result: Array ( [0] => href = http://www.111cn.net [1] => [2] => Http://www.111cn.net ) Array ( [0] => href = 'http: // www.111cn.net' [1] => Http://www.111cn.net ) Array ( [0] => href = "export cnames: href ('test ');" [1] => export cnames: href ('test '); ) |
/Href \ s * = \ s *(? : "([^"] *) "| \ '([^ \'] *) \ '| ([^" \'> \ S] + ))/
The idea is clever:
In two steps, configure the tag first, and then configure the link in the tag.