Home >Backend Development >PHP Tutorial > 正则表达试!100分等带

正则表达试!100分等带

WBOY
WBOYOriginal
2016-06-13 13:53:06888browse

求一个正则表达试!!急急急急!100分等带
类似这样的一个连接:
                                                href= "http://url "   target= "_blank "> 标题
或者是
                                                href= "http://url "> 标题
等等这样的连接:
我需要使用   preg_match_all   得到一个   url和标题.数组.
等带中.希望赐教.马上给分


------解决方案--------------------
# ]+href=([ '\ "]?)(.+)\\1[^> ]*> (.*) #isU
------解决方案--------------------
preg_match_all( '/
]+href[\s\r\n]*=[\s\r\n]*([ '\ "]?)(.+)\1[^> ]*> (.+) /isU ',$text,$matches);

------解决方案--------------------
@href= "(.*) ".*> (.*) @isU

示例:

$str =
href= "http://url " target= "_blank "> 标题
或者是

href= "http://url "> 标题
EOF;

preg_match_all( "@href=\ "(.*)\ ".*> (.*) @isU ",$str,$matches);

print_r( '

  '); <br> print_r($matches); <br> ?>  <br> 输出: <br> Array <br> ( <br>     [0] =>  Array <br>         ( <br>             [0] =>  href= "http://url " target= "_blank "> 标题  <br>             [1] =>  href= "http://url "> 标题  <br>         ) <br>  <br>     [1] =>  Array <br>         ( <br>             [0] =>  http://url <br>             [1] =>  http://url <br>         ) <br>  <br>     [2] =>  Array <br>         ( <br>             [0] =>  标题 <br>             [1] =>  标题 <br>         ) <br>  <br> ) <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn