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?
Asked
Active
Viewed 108 times
-1

Harry Wardana
- 277
- 1
- 5
- 15
-
from a string? there's this thing called `strpos` and `substr` in php – Kevin Jun 19 '20 at 07:30
-
You can use `chop()` function, answer has given below. – STA Jun 19 '20 at 07:40
1 Answers
0
You can use explode()
to convert the string
to an array
and then get what you want. Like so -
$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

sauhardnc
- 1,961
- 2
- 6
- 16