douyan6548 2014-06-09 22:35
浏览 49
已采纳

Preg_match_all从字符串中获取值

Example:

$word = "Your IP address=10.0.0.1</br>my ip address=127.0.0.1</br>";

how can i taking that ip address string using preg_match_all?

  • 写回答

1条回答 默认 最新

  • dtcuv8044 2014-06-09 22:42
    关注

    A pragmatic attempt in this case would be to match everything between the = and the </br>:

    preg_match_all('~=(.*?)</br>~', $string, $matches);
    var_dump($matches);
    

    Note the ? which marks an ungreedy match. If you omit that you would get the following match:

    10.0.0.1</br>my ip address=127.0.0.1
    

    Of course you need preg_match_all() to get every match (IP) an not just the first.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?