I have a string as
$line = \"Name=johnGender=M\";
How to make a string called $name
that will have a value stored as joh
I guess the following would work for you.
$name = array();
foreach($line as $elem)
array_push($name,substr(explode("=",$elem)[1],0,4));
So you can access it as $name[0],$name[1],...
Better try to have the input syntax as
$line = array("Name=john&Gender=M","Name=raja&Gender=M");
parse_str($line);
So you can use the built-in function parse_str()
.
Now $Name[0]
contains john and $Name[1]
contains raja.