一个字符串的每个值到一个单独的数组转换
Each value of a string to a separate array conversion
我有一个 html 页面内容,我将其转换为以“#”分隔的字符串。
示例:
(2R)-2-hydroxy#250.181#C15H24NO2#2#1#46#1#11#1.1266#1#18#6
有什么方法可以将这些字符串的每个值转换成数组吗?
我需要这样的输出:
$a = (2R)-2-hydroxy
$b = 250.181
$c = C15H24NO2
$d = 2
$e = 1
//etc...
这应该适合你:
就explode()
your string and loop through the array. Then you can assign each value to a variable, where you can increment the character.
$str = "(2R)-2-hydroxy#250.181#C15H24NO2#2#1#46#1#11#1.1266#1#18#6";
$arr = explode("#", $str);
$start = "a";
foreach($arr as $v) {
$$start = $v;
$start++;
}
这应该有效
$array = explode("#", "(2R)-2-hydroxy#250.181#C15H24NO2#2#1#46#1#11#1.1266#1#18#6");
$array [0] = (2R)-2-hydroxy
$array [1] = 250.181
...
我有一个 html 页面内容,我将其转换为以“#”分隔的字符串。
示例:
(2R)-2-hydroxy#250.181#C15H24NO2#2#1#46#1#11#1.1266#1#18#6
有什么方法可以将这些字符串的每个值转换成数组吗?
我需要这样的输出:
$a = (2R)-2-hydroxy
$b = 250.181
$c = C15H24NO2
$d = 2
$e = 1
//etc...
这应该适合你:
就explode()
your string and loop through the array. Then you can assign each value to a variable, where you can increment the character.
$str = "(2R)-2-hydroxy#250.181#C15H24NO2#2#1#46#1#11#1.1266#1#18#6";
$arr = explode("#", $str);
$start = "a";
foreach($arr as $v) {
$$start = $v;
$start++;
}
这应该有效
$array = explode("#", "(2R)-2-hydroxy#250.181#C15H24NO2#2#1#46#1#11#1.1266#1#18#6");
$array [0] = (2R)-2-hydroxy
$array [1] = 250.181
...