php字符串拼接join,9.3.4 字符串的分割与连接(explode、implode join、preg_split)

9.3.4 字符串的分割与连接(explode、implode join、preg_split)

2.php

/* $reg = '/(https?|ftps?):\/\/(www|mail|bbs|ftp)\.(.*?)\.(net|com|org|cn)([\w-\.\/\=\?\&\%]*)?/';

$reg = '/\w+([+-.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* /i';

* 分割、匹配、查找、替换

*

* 1. 字符串处理函数 (处理快, 但有一些做不到)

*

* 2. 正则表达式函数 (功能强大,但效率要低)

*

*

* 注意:如果可以直接使用字符串处理函数处理的字符串,就不要使用正则处理

*

*

*

* 匹配查找:

*

* strstr strpos substr

*

*

* 正则匹配查找

*

* preg_match() preg_match_all() preg_grep();

*

*

* 分割:

* explode() implode() -- join()

*

*

*正则表达式

preg_split()

*

*

*/

header("Content-Type:text/html;charset=utf-8");

$str = "this is a test.

hello word,

ni hao.

";

// print_r( explode("mn", $str, 3) );

print_r( preg_split('/[.,!? ]/', $str, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_OFFSET_CAPTURE ) );

test.php

/* $reg = '/(https?|ftps?):\/\/(www|mail|bbs|ftp)\.(.*?)\.(net|com|org|cn)([\w-\.\/\=\?\&\%]*)?/';

$reg = '/\w+([+-.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* /i';

* 分割、匹配、查找、替换

*

* 1. 字符串处理函数 (处理快, 但有一些做不到)

*

* 2. 正则表达式函数 (功能强大,但效率要低)

*

*

* 注意:如果可以直接使用字符串处理函数处理的字符串,就不要使用正则处理

*

*

*

* 匹配查找:

*

* strstr strpos substr

*

*

* 正则匹配查找

*

* preg_match() preg_match_all() preg_grep();

*

*

* 分割:

* explode() implode() -- join()

*

*

*正则表达式

preg_split()

*

*

*/

header("Content-Type:text/html;charset=utf-8");

$str = "lamp";

// print_r( explode("mn", $str, 3) );

$arr=preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);

echo implode("++++",$arr)."
";

list($a, $b) = explode("_", "mei_zi");

echo $a."
";

echo $b."
";

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值