I have a string like this : xxxxxxx=921919291&arg3=3729ABNTSC980z2MNM3573&arg2=2025102&arg1=7e266505e183fcb31d0ba493008fa9f881af6746
.
i want to keep only the xxxxxxx=921919291
(this one is variable so i can't use an strpos)
I have tried an explode of &
caractere then show only the 0 one but i have a lot of string in the same variable so it would not but good.
STR_REPLACE
dosn't seems to be good because all caracteres after the =
caractere are variable.
use parse_str
$str = "xxxxxxx=921919291&arg3=3729ABNTSC980z2MNM3573&arg2=2025102&arg1=7e266505e183fcb31d0ba493008fa9f881af6746";
parse_str($str);
echo $xxxxxxx;
You can also place your values into an array like so:
$str = "xxxxxxx=921919291&arg3=3729ABNTSC980z2MNM3573&arg2=2025102&arg1=7e266505e183fcb31d0ba493008fa9f881af6746";
parse_str($str, $output);
echo $output['xxxxxxx'];
More information can be found here: http://php.net/manual/en/function.parse-str.php
Try this:
echo array_shift(explode('&', $string));
You should look into phps capturing groups, an expression like this, should sort you:
^([^&]+)
This will populate capture group 1, which is accessed using the parameter of the preg_match call as an array element.