V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
supman
V2EX  ›  问与答

可耻的伸个手, 关于正则

  •  
  •   supman · Apr 24, 2015 · 2046 views
    This topic created in 4029 days ago, the information mentioned may be changed or developed.

    <span class="a"><div class="userID" title="189">189</div></span>
    <span class="b"><div class="userID" title="190">190</div></span>
    <div class="userGroup" title="2">2</div>

    麻烦大家帮忙想想法子, 能不能只提取 第一行的数字 189, 不论是title 还是标签对内的, 只要能提取到就好。

    5 replies    2015-04-24 08:38:45 +08:00
    xiaogui
        1
    xiaogui  
       Apr 24, 2015
    先用 class=“a” 提取,不久好提取了吗?
    laoyuan
        2
    laoyuan  
       Apr 24, 2015
    preg_match("/<span class=\"a\">.+?title=\"(\d+)/", $str, $match);
    laoyuan
        3
    laoyuan  
       Apr 24, 2015
    结果
    Array
    (
    [0] => <span class="a"><div class="userID" title="189
    [1] => 189
    )
    kasp
        4
    kasp  
       Apr 24, 2015
    phpquery可以轻松搞定
    supman
        5
    supman  
    OP
       Apr 24, 2015
    @laoyuan

    感谢 :)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2631 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 11:52 · PVG 19:52 · LAX 04:52 · JFK 07:52
    ♥ Do have faith in what you're doing.