php preg_match 匹配title,preg_match 匹配特定字符后面的内容

1、需求

如下内容,获取JSESSIONID后面的6F2FB1EA915913DEF3256D11101F1DF3

# Netscape HTTP Cookie File

# http://curl.haxx.se/rfc/cookie_spec.html

# This file was generated by libcurl! Edit at your own risk.

account.chsi.com.cnFALSE/passportFALSE0JSESSIONID6F2FB1EA915913DEF3256D11101F1DF3

2、实现

通过preg_match实现

$content = "# Netscape HTTP Cookie File

# http://curl.haxx.se/rfc/cookie_spec.html

# This file was generated by libcurl! Edit at your own risk.

account.chsi.com.cnFALSE/passportFALSE0JSESSIONID6F2FB1EA915913DEF3256D11101F1DF3";

$pattern = "/JSESSIONID([0-9A-Z]+)/i";

$match = preg_match($pattern,$content,$matches);

var_dump($matches);

var_dump($match);

?>

daffe9c8037672298c1d072d62da01d1.png

3、延伸

1)$pattern = "/JSESSIONID([0-9A-Z]+)/i";

2)$pattern = "/JSESSIONID([0-9A-Z])+/i";

1)和2)的区别 +的位置在括号内和括号外

$matches[1] 返回的是括号内的内容,所以1)可以返回所有,2)只能返回一个数字

790bb5ebc679896ea48a88a664fc6e5c.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值