Question : problem with string

I'm using the following code where {system_details} is template variable that is actually equal to the commented string below:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
$string = "{system_details}";
//$string = "Pistons, Cylinders, Collar Assemblies, Brace Assemblies, Crank Assemblies, Hooks and related hardware";
$array = preg_split("/[\s]*[,][\s]*/", $string);
print_r($array);		

$count = count($array);
		
for ($i = 0; $i < $count; $i++) {
echo "<li>{$array[$i]}</li>";
}


The problem is it's not splitting it at all. so instead of returning:
1:
Array ( [0] => Pistons [1] => Cylinders [2] => Collar Assemblies [3] => Brace Assemblies [4] => Crank Assemblies [5] => Hooks and related hardware ) 


it returns:
1:
Array ( [0] => Pistons, Cylinders, Collar Assemblies, Brace Assemblies, Crank Assemblies, Hooks and related hardware ) 


What is keeping it from splitting the elements? Is it not seeing it as the correct string type? If I swap out the template variable with the text it works as it is supposed to.

Answer : problem with string

Okay, different tack.
ExpressionEngine "input" stage refers only to PHP parsing.
It still only parses the expressions at output stage, so we'll make PHP output it and capture it back.

$string = "{system_details}";
ob_start();
echo $string;
$string = ob_get_contents();
ob_end_clean();
//$string = "Pistons, Cylinders, Collar Assemblies, Brace Assemblies, Crank Assemblies, Hooks and related hardware";
$array = preg_split("/[\s]*[,][\s]*/", $string);
print_r($array);
Random Solutions  
 
programming4us programming4us