我有一个 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()
你的字符串并循环遍历数组。然后您可以将每个值分配给一个变量,您可以在其中 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++;
}
关于php - 将字符串的每个值转换为单独的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31337044/