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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

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

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Untested...

Code: Select all

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

foreach ($valuesArray as $value) {
    echo $value;
}
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Post 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 ","
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

See if strpos() can help.
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

Post by wtf »

substr_replace() should do the job


Code: Select all

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