search

Home  >  Q&A  >  body text

php - How to extract this through regular expression

</li><li class="active"><a href="javascript:;">2</a>

How to extract 2 using regular expression in php?
2 is a variable

PHPzPHPz2779 days ago468

reply all(3)I'll reply

  • 世界只因有你

    世界只因有你2017-05-16 13:17:16

    $patt = '/<\/li><li class="active"><a href="javascript:;">(\d+)<\/a>/';
    $str = '</li><li class="active"><a href="javascript:;">2</a><li></a>';
    preg_match($patt, $str,$arr);
    var_dump($arr[1]);

    For this thing, you should check how to use it only when you are using it. After all, you don’t use it much.

    reply
    0
  • 为情所困

    为情所困2017-05-16 13:17:16

    '</li><li class="active"><a href="javascript:;">2</a>'.replace(/.+<li[^>]+class="active"><a[^>]+>(.+)<\/a>/,'$1')

    reply
    0
  • PHPz

    PHPz2017-05-16 13:17:16

    The explanation above is so comprehensive

    reply
    0
  • Cancelreply