Can someone please post a code that will return a number of how many instances of a string are in a string? For example: "my name is tim tim is a dumb name i hate people named tim" I want a code to return "3" (for the 3 instances of tim) for that. Please help!
Thanks nico but would this return the same if the word was a part of a word like "tim went to timhorton" substr_count would return 2 while the real would return 1 . right ?
Yep, that's right. However, the OP didn't state whether he wants to count these occurrences or not. We'll see I guess.
in javascript, you can easily do that using regular expressions. i guess thats available in php as well. pls chek on that ..........
Yes I am. And nice one. I never got around Java. Yes, you could also use preg_match_all(). It might even be faster than the explode/foreach version. Not sure though. $word = 'tim'; $occurrences = preg_match_all("~(^|\s){$word}(\s|$)~", $string); echo $occurrences; PHP: Untested but should do the job as well.
Why don't you go to w3schools.com. I hope then you can find it by your self. best wishes. _______________________ Custom lanyards are here.
you should be banned 1- your post is worthless 2- you are spamming with a fake link in your signature 3- we are not stupid here it's DP grow up kid