PHP 中的 preg_match()函数

首页 / PHP入门教程 / PHP 中的 preg_match()函数

preg_match() - 语法

int preg_match (string pattern, string string [, array pattern_array], [, int $flags [, int $offset]]]);

preg_match()函数在字符串中搜索pattern,如果存在pattern,则返回true,否则返回false。

如果提供了可选的输入参数pattern_array,则pattern_array将包含搜索模式中包含的子模式的各个部分(如果适用)。

preg_match() - 返回值

  • 如果存在,则返回true,否则返回false。

preg_match() - 示例

<?php
   $line="Vi is the greatest word processor ever created!";
   //perform a case-Insensitive search for the word "Vi"
   
   if (preg_match("/\bVi\b/i", $line, $match)) :
      print "Match found!";
      endif;
?>

这将产生以下输出-

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/php/php-preg-match.html

来源:LearnFk无涯教程网

Match found!

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

机器学习40讲 -〔王天一〕

玩转Spring全家桶 -〔丁雪丰〕

Web安全攻防实战 -〔王昊天〕

Go 并发编程实战课 -〔晁岳攀(鸟窝)〕

如何成为学习高手 -〔高冷冷〕

编程高手必学的内存知识 -〔海纳〕

徐昊 · TDD项目实战70讲 -〔徐昊〕

快手 · 移动端音视频开发实战 -〔展晓凯〕

Web 3.0入局攻略 -〔郭大治〕

好记忆不如烂笔头。留下您的足迹吧 :)