PDA

View Full Version : PHP function similar to VB INSTR()?


kyrnel
02-15-2004, 11:34 PM
I need a PHP function to count the number of occurances of one string inside another string. You can do this in Visual Basic with the Instr() function, but I can't find an equivalent in PHP.

Specifically I want to count the number of commas in $birthdays. If I add one, then I will get the number of birthdays without having to run another query. (that is, assuming the string is not zero-length).

Anyone have any ideas? Thanks in advance.

NTLDR
02-16-2004, 09:56 AM
If your using vB3 then you can use its fetch_character_count() function or you can use substr_count() (http://uk2.php.net/manual/en/function.substr-count.php).

kyrnel
02-16-2004, 12:32 PM
Thanks! That does it but for some reason I can't add to the number returned.

I'm a PHP n00B :(

This is what I have so far:
$numbirthdays = fetch_character_count($birthdays, ",")+1;

I need to add a one to the number since there are one fewer commas then there are birthdays. But this only returnes the number of commas. It doesnt seem to be adding the 1. Probably my syntax is bad.

I'm reading PHP.net now to see what I did wrong.

Also, KirbyDE was kind enough to write a full-on hack to display the number of birthdays on the main page:
https://vborg.vbsupport.ru/showthread.php?t=61610