Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

problem with string

Avatar of befidled
befidled asked on
PHP
50 Comments1 Solution393 ViewsLast Modified:
I'm using the following code where {system_details} is template variable that is actually equal to the commented string below:

$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:
Array ( [0] => Pistons [1] => Cylinders [2] => Collar Assemblies [3] => Brace Assemblies [4] => Crank Assemblies [5] => Hooks and related hardware ) 

it returns:
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.