vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   PHP function similar to VB INSTR()? (https://vborg.vbsupport.ru/showthread.php?t=61605)

kyrnel 02-15-2004 11:34 PM

PHP function similar to VB INSTR()?
 
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


All times are GMT. The time now is 06:39 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00966 seconds
  • Memory Usage 1,712KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete