joebudden Posted April 17, 2007 Share Posted April 17, 2007 is there any way to count the occurences of a certain character into a variable ??? $string = (1,2,3,4,5); $test = explode(",", $string); in this example there are 4 commas any help please Link to comment https://forums.phpfreaks.com/topic/47335-solved-quick-question/ Share on other sites More sharing options...
fert Posted April 17, 2007 Share Posted April 17, 2007 $count=0; foreach($test as $t) { if($t==',') $count++; } I'm sure there are easier ways of doing it, but what kind of php is this? $string = (1,2,3,4,5); Link to comment https://forums.phpfreaks.com/topic/47335-solved-quick-question/#findComment-230901 Share on other sites More sharing options...
joebudden Posted April 17, 2007 Author Share Posted April 17, 2007 yer .. i think iv found what im looking for in the manual Link to comment https://forums.phpfreaks.com/topic/47335-solved-quick-question/#findComment-230904 Share on other sites More sharing options...
joebudden Posted April 17, 2007 Author Share Posted April 17, 2007 just used this $string = "1,2,3"; $count = substr_count($string,", "); Link to comment https://forums.phpfreaks.com/topic/47335-solved-quick-question/#findComment-230905 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.