preg_match_all和array_slice是什么函数??在哪能查到这些函数的用法??

kxyes 2003-09-11 03:52:29
如题
...全文
42 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
1fairy1 2003-09-11
  • 打赏
  • 举报
回复
preg_match_all
字符串整体比对解析。

语法: int preg_match_all(string pattern, string subject, array matches, int [order]);

返回值: 整数

函数种类: 资料处理




内容说明


本函数以 pattern 的规则来整体解析比对字符串 subject。比对结果返回的值放在数组参数 matches 之中,并依顺序值 order 排序。参数 order 的值有 PREG_PATTERN_ORDER 及 PREG_SET_ORDER 二种。若没有 order 值,则系统自动以 PREG_PATTERN_ORDER 代入 order 值中。返回值为合乎比对结果的数目,若没有或错误则返回 false 值。




使用范例


PREG_PATTERN_ORDER 的例子

<?php
preg_match_all("|<[^>]+>(.*)</[^>]+>|U", "<div align=left>a test</div>", $out, PREG_PATTERN_ORDER);
print $out[0][0].", ".$out[0][1]."\n";
print $out[1][0].", ".$out[1][1]."\n"
?>

返回值为

<b>example: </b>, <div align=left>this is a test</div>
example: , this is a test




PREG_SET_ORDER 的例子

<?php
preg_match_all("|<[^>]+>(.*)</[^>]+>|U", "<div align=left>a test</div>", $out, PREG_SET_ORDER);
print $out[0][0].", ".$out[0][1]."\n";
print $out[1][0].", ".$out[1][1]."\n"
?>

返回值为

<b>example: </b>, example:
<div align=left>this is a test</div>, this is a test
______________________________________________________________________________

xuzuning 2003-09-11
  • 打赏
  • 举报
回复
手册上都有
preg_match_all与preg_match相似
array_slice与substr相似,只是前者是对数组操作

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧