本文实例讲述了 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.";
- }
- ?>
来源: https://www.php1.cn/detail/php-db1a592ccb.html