PHP速学教程(入门到精通)
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
我要取出 字符串"user=asdasd; token=dwwewee; type=assdfs" 里的token值dwwewee,
php怎么写?
真的不会写。。
这样好像也不行
<code>preg_match("/(token=)(.*?)(;|$)/i","user=asdasd; token=dwwewee; type=assdfs", $matches); foreach ($matches as $m) { echo $m;echo "<br>"; } </code>
我要取出 字符串"user=asdasd; token=dwwewee; type=assdfs" 里的token值dwwewee,
php怎么写?
真的不会写。。
这样好像也不行
<code>preg_match("/(token=)(.*?)(;|$)/i","user=asdasd; token=dwwewee; type=assdfs", $matches); foreach ($matches as $m) { echo $m;echo "<br>"; } </code>
<code>(?<=token=).*(?=;) </code>
<code>if (preg_match("/(token=)(.*?)(;|$)/i","user=asdasd; token=dwwewee; type=assdfs", $matches)) { print_r($matches[2]); } </code>
如果匹配成功,那么会把结果存放在$matches这个array中,index 0 是匹配的完整字符串,1 是你第一个括号, 2 是第二个括号,依次类推。从你的需求看,你需要的值是出现在第二个括号,所以取值 $matches[2]
<code>php</code><code>//php5.6 echo explode('=',explode(';',$str)[1])[1];//dwwewee $arr = explode(';',"user=asdasd; token=dwwewee; type=assdfs"); $arr2 = explode('=',$arr[1]); echo $arr2[1];//dwwewee </code>
php免费学习视频:立即学习
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!
已抢7336个
抢已抢95475个
抢已抢14938个
抢已抢52727个
抢已抢195931个
抢已抢87512个
抢