hassank1 Posted January 8, 2009 Share Posted January 8, 2009 is there a built in php function to return the occurence of a char in a string? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted January 8, 2009 Share Posted January 8, 2009 Try here. Seriously, try actually looking in the manual. Unlike most manuals, it is actually an incredibly useful resource. Quote Link to comment Share on other sites More sharing options...
hassank1 Posted January 8, 2009 Author Share Posted January 8, 2009 I've tried google but I didn't find a build in function. ofcourse I can do my own function but a php one is faster. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 8, 2009 Share Posted January 8, 2009 #1) I LOVE http://letmegooglethatforyou.com/ ....it's fantastic the OP asked about occurrences of A character though. to my knowledge, there is no built in function...there are lot's of other ways to do it though. one easy way that comes to mind is to split on it: <?php $str = "Hello World!"; $find = 'o'; $count = count(explode($find,$str)) - 1; print $count; ?> Quote Link to comment Share on other sites More sharing options...
hassank1 Posted January 8, 2009 Author Share Posted January 8, 2009 why the -1 ?? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted January 8, 2009 Share Posted January 8, 2009 substr_count would do it. Quote Link to comment Share on other sites More sharing options...
hassank1 Posted January 8, 2009 Author Share Posted January 8, 2009 great .. thx guys Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 8, 2009 Share Posted January 8, 2009 EXPLODE = SPLIT. If you split on a character, you will get 1 more then you need BEFORE|MIDDLE|AFTER splitting on | will yield 3, when we really need 2 edit: damn....there is a function Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.