PHP 正则表达式
/
在 PHP 中,如果只是匹配一次结果请使用
preg_match
函数
<?php
//字符串
$str = 'Hello World Hello PHP';
//正则表达式
$regular = '/Hell/';
//执行匹配正则表达式
preg_match($regular, $str, $matches);
//打印结果
echo '<pre>';
print_r($matches);
echo '</pre>';
输出结果
Array
(
[0] => Hell
)
本文章首发在 LearnKu.com 网站上。
推荐文章: