php and need help on how to split strings!?

evachick156

New member
I have the following string read from database
$rows['string'] = "Teach t1, t2, t3 ; Practice p2"

What im trying to do is put "Teach" into $teach variable and "Practice" into $pract variable.
But i need t1, t2, t3 in an array, and than p2 into another array...please help! Here is my code but its not working on how i want it....

$string = trim($rows['string'], "Teach");
$string = trim($string, ";");
$string = trim($string, "Practice");
$str = explode(',', $string);
$rw0 = $str[0];
$rw1 = $str[1];
$rw2 = $str[2];
$rw3 = $str[3];
 
$string = explode(';', $rows['string']);
$teach[0] = 'Teach';
$string[0] = trim($string[0], 'Teach ');
$teach[1] = explode(',', $string[0]);
$pract[0] = 'Practice';
$string[1] = trim($string[1], 'Practice ');
$pract[1] = explode(',', $string[1]);

$teach[0] is Teach
$teach[1] holds the array(t1, t2, t3)

$pract[0] is Practice
$pract[1] holds the value or array p2
 
Back
Top