如何截断字符串,或从 php 中的字符串中提取部分值
how to truncate the string, or to extract a portion of the value from a string in php
hello , i have value 1284&kec=220107&prop=220000
here i want to take the numbers in front & the numbers in front
are not always three letters, sometimes two letters and sometimes
also one, how to remove or delete values after &
example : 1284&kec=220107&prop=220000
result value = 1284
example : 11&kec=2332&prop=563454
result value = 11
can you give an example?
您可以使用 explode()
将 string
转换为 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
hello , i have value 1284&kec=220107&prop=220000
here i want to take the numbers in front & the numbers in front are not always three letters, sometimes two letters and sometimes also one, how to remove or delete values after &
example : 1284&kec=220107&prop=220000 result value = 1284 example : 11&kec=2332&prop=563454 result value = 11
can you give an example?
您可以使用 explode()
将 string
转换为 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