为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
青春有我 2023-06-18 17:48:04
你好,我有值 1284&kec=220107&prop=220000这里想取前面的数字& 前面的数字不一定都是三个字母,有时是两个字母有时也是一个,如何去掉或删除&后面的值example : 1284&kec=220107&prop=220000result value = 1284example : 11&kec=2332&prop=563454result value = 11你能给个例子吗?
查看完整描述

1 回答

?
桃花长相依

TA贡献1860条经验 获得超8个赞

您可以使用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


查看完整回答
反对 回复 2023-06-18
  • 1 回答
  • 0 关注
  • 90 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信