Each value of a string to a separate array conversion

I have a html page contents, that I converted into a string separated by "#".

Example:

(2R)-2-hydroxy#250.181#C15H24NO2#2#1#46#1#11#1.1266#1#18#6

Is there any way to convert each value of these string to convert into a array?

I need an output like this:

$a = (2R)-2-hydroxy    
$b = 250.181    
$c = C15H24NO2   
$d = 2    
$e = 1
//etc...

Answers


This should work for you:

Just 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++;
}

This should work

$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
...

Need Your Help

import database schema from database to a DataSet (with DataRelations)

c# .net ado.net dataset

I'm trying to import the schema of NorthWind database to DataSet using VS2010, and .Net Framework 4.

jQuery unbinding a plugin event

jquery binding

I've never needed to 'bind' or 'unbind' anything before so I'm getting confused because I can't find an example that directly relates to what I want to do.