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

一段简单的正则,请问

WBOY
Release: 2016-06-13 13:33:34
Original
863 people have browsed it

一段简单的正则,请教

PHP code
<!--

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

-->$content = 
Copy after login
  • 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.>
    Copy after login
    Related labels:
    source:php.cn
    Statement of this Website
    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
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template