Page 1 of 1

how to separate the values separated by "," ???

Posted: Thu Jul 20, 2006 9:01 am
by PHPycho
Hello friends and seniors over there...
Here's my prob ..searching for the solution..
i had made a table for marks obtained by student called "tb_score" with fields like
score_id,st_id,exam_type,sub_id_set,mo_set,remarks_set,percentage,result .
In fields like sub_id_set,mo_set,remarks_set i had inserted the values separated by comma for EX: ",value1,value2,value3 etc."
I am getting prob in retrieving the values separated by comma....can anybody help me in retrieving the values separated by comma with a bit code.....
Thanks in advance

Posted: Thu Jul 20, 2006 9:14 am
by Benjamin
Untested...

Code: Select all

$valuesArray = explode(',', $commaDelimitedValues);

foreach ($valuesArray as $value) {
    echo $value;
}

Posted: Thu Jul 20, 2006 10:33 am
by PHPycho
Thanks a lot ..
i got my prob a great bit solved..
i want to know how to strip the first comma from the value
$values = ",value1,value2,value3 etc";
so as to get the "value1,value2,value3 etc" excluding the first ","

Posted: Thu Jul 20, 2006 10:40 am
by RobertGonzalez
See if strpos() can help.

Posted: Thu Jul 20, 2006 10:49 am
by wtf
substr_replace() should do the job


Code: Select all

$values = ',value1,value2,value3';
  
  echo substr_replace( $values, '', 0, 1 );