SunQuest
           PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old July 23rd, 2002, 03:43 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
does substr_count work?

heres the deal, I'm using a bit of code:

$x = substr_count($word, $guess);

Imagine the game hangman, you want to know if the letter you guessed is in the hidden word.

Using echos I can prove that, for example $word = akira
and $guess = a
and $x = 0

Naturally I'm not pleased, I tried switching the variable order, which is wrong and it does exactly the same. I'm open to suggestions as to why it might not be working and fixes, at present I'm hoping to avoid writing a loop to go through each character checking the whole word and figuring out what to do at the end but thats mostly because I am lazy.

Alan Bundock

gamer extrordinaire. But that don't mean I'm good

Reply With Quote
  #2  
Old July 23rd, 2002, 04:36 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: does substr_count work?

This code:
php Code:
Original - php Code
  1. <?
  2. $word = 'akira';
  3. $guess = 'a';
  4. $x = substr_count($word, $guess);
  5. echo $x;
  6. ?>


works as expected for me. It echos out the number 2. Can you show some example code that doesn't work?

Reply With Quote
  #3  
Old July 23rd, 2002, 05:02 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: does substr_count work?

Okay I was using substr_count in an if statement, i.e. if it returned a count greater than zero. By creating a variable first, performing the operation and then using the new variable in the if statement it seems to be working. Why this should make a difference I'm not sure.

Once again thanks for your contributions.

Alan Bundock

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > does substr_count work?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway