Home  >  Article  >  Backend Development  >  一段简单的正则,请问

一段简单的正则,请问

WBOY
WBOYOriginal
2016-06-13 13:33:34784browse

一段简单的正则,请教

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->$content = 
  • html; $parr = "/href=\"\/html5\/(.*)\"/i"; preg_match_all($parr, $content, $result); var_dump($result);
    匹配到的结果如下 
    string(30) "tag_comment.asp" title="HTML 5"
    string(15) "tag_doctype.asp"

    第一个还包含了 title 属性。 我的本意是只取href属性的值,该怎么做?

    ------解决方案--------------------
    $parr = "/href=\"\/html5\/(.*?)\"/i";



    array(2) {
    [0]=>
    array(2) {
    [0]=>
    string(29) "href="/html5/tag_comment.asp""
    [1]=>
    string(29) "href="/html5/tag_doctype.asp""
    }
    [1]=>
    array(2) {
    [0]=>
    string(15) "tag_comment.asp"
    [1]=>
    string(15) "tag_doctype.asp"
    }
    }

    ------解决方案--------------------
    我一直用这个,忘了从哪里找的了。反正我是看不懂,只管用
    PHP code
    
    '/<a.>(.+?)/sim' <div class="clear">
                     
                  
                  
            
                </div></a.>
    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