php使用正则表达式进行字符串搜索的方法

6年以前  |  阅读数:887 次  |  编程语言:PHP 

本文实例讲述了php使用正则表达式进行字符串搜索的方法。分享给大家供大家参考。具体实现方法如下:


    <?php
    $string_to_search = "jb51.net";
    $regex = "/tor/";
    $num_matches = preg_match($regex, $string_to_search);

    if ($num_matches > 0) {
     echo "Found a match!";
    } else {
     echo "No match. Sorry.";
    }
    ?>

希望本文所述对大家的php程序设计有所帮助。

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8