如何截断字符串,或从 php 中的字符串中提取部分值

你好,我有值 1284&kec=220107&prop=220000


这里想取前面的数字& 前面的数字不一定都是三个字母,有时是两个字母有时也是一个,如何去掉或删除&后面的值


example : 1284&kec=220107&prop=220000

result value = 1284


example : 11&kec=2332&prop=563454

result value = 11

你能给个例子吗?


青春有我
浏览 94回答 1
1回答

桃花长相依

您可以使用explode()将 the 转换string为 an array,然后得到您想要的。像这样-$example = '1284&kec=220107&prop=220000';$ex = explode("&kec", $example); // convert it to array where $kec is found$value = $ex[0]; // output: 1284 // the first key will hold the value before $kec$example2 ='11&kec=2332&prop=563454';$ex = explode("&kec", $example2);$value = $ex[0]; // output: 11
打开App,查看更多内容
随时随地看视频慕课网APP