php正则匹配怎么写,正则表达式 - 求助怎么写php的正则匹配
我要取出 字符串"user=asdasd; token=dwwewee; type=assdfs" 里的token值dwwewee,
php怎么寫?
真的不會寫。。
這樣好像也不行
preg_match("/(token=)(.*?)(;|$)/i","user=asdasd; token=dwwewee; type=assdfs", $matches);
foreach ($matches as $m)
{
echo $m;echo "
";
}
回復內容:
我要取出 字符串"user=asdasd; token=dwwewee; type=assdfs" 里的token值dwwewee,
php怎么寫?
真的不會寫。。
這樣好像也不行
preg_match("/(token=)(.*?)(;|$)/i","user=asdasd; token=dwwewee; type=assdfs", $matches);
foreach ($matches as $m)
{
echo $m;echo "
";
}
(?<=token=).*(?=;)
if (preg_match("/(token=)(.*?)(;|$)/i","user=asdasd; token=dwwewee; type=assdfs", $matches)) {
print_r($matches[2]);
}
如果匹配成功,那么會把結果存放在$matches這個array中,index 0 是匹配的完整字符串,1 是你第一個括號, 2 是第二個括號,依次類推。從你的需求看,你需要的值是出現在第二個括號,所以取值 $matches[2]
php//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
本文原創發布php中文網,轉載請注明出處,感謝您的尊重!
總結
以上是生活随笔為你收集整理的php正则匹配怎么写,正则表达式 - 求助怎么写php的正则匹配的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 三维错切变换矩阵_图像的仿射变换
- 下一篇: 计算机应用技术环境评估,计算机应用教程(