I have a code in php that needs to be upgraded the situation

Reply

Join Date: Jul 2008
Posts: 58
Reputation: masterjiraya is an unknown quantity at this point 
Solved Threads: 0
masterjiraya masterjiraya is offline Offline
Junior Poster in Training

I have a code in php that needs to be upgraded the situation

 
0
  #1
Sep 14th, 2009
  1. <html>
  2. <title>
  3. consonants vowels and numbers
  4. </title>
  5. <body bgcolor=red text=white><form method=post><font size=15>
  6. Enter a word(s):<input type=text name='phrase'></br>
  7. <input type=submit value=generate></br>
  8. <?php
  9. $vowel;
  10. $conso;
  11. $nums;
  12. switch($_POST['phrase']){
  13. case'a':
  14. case'A':
  15. case'E':
  16. Case'e':
  17. Case'I':
  18. case'i':
  19. case'O':
  20. case'o':
  21. case'U':
  22. case'u':
  23. $vowel+=1;
  24. break;
  25. case'0':
  26. case'1':
  27. case'2':
  28. case'3':
  29. case'4':
  30. case'5':
  31. case'6':
  32. case'7':
  33. case'8':
  34. case'9':
  35. $nums+=1;
  36. break;
  37. default:
  38. $conso+=1;
  39. break;
  40. }
  41.  
  42. echo"Vowels:",$vowel;
  43. echo"</br>";
  44. echo"Consonants:",$conso;
  45. echo"</br>";
  46. echo"Numbers:",$nums;
  47. echo"</br>";
  48. ?>
  49.  
  50. <input type=reset value=reset>
  51. </font>
  52. </form>
  53. </body>
  54. </html>

can someone tell me how to do it on full string type???
I need to count consonants the vowels and the numbers disregarding the spaces and special characters
Last edited by Ezzaral; Sep 14th, 2009 at 5:39 pm. Reason: Fixed code tags.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 25
Reputation: Rkeast is an unknown quantity at this point 
Solved Threads: 2
Rkeast Rkeast is offline Offline
Light Poster

Re: I have a code in php that needs to be upgraded the situation

 
0
  #2
Sep 14th, 2009
You can access single characters within a string by using square brackets like the string is an array.

Using this method you could use code like this:

  1. $inputString = $_POST['phrase'];
  2. for($i = 0; $i < strlen($inputString); $i++)
  3. {
  4. $stringChar = $inputString[$i];
  5. switch($stringChar)
  6. {
  7. //your switch statement code here
  8. }
  9. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,087
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 137
ardav's Avatar
ardav ardav is offline Offline
Veteran Poster

Re: I have a code in php that needs to be upgraded the situation

 
0
  #3
Sep 14th, 2009
You may find using regex in the switch area may be more efficient than multiple case statements.

vowels = [AEIOUaeiou], etc.
Happy Humbugging Christmas
Reply With Quote Quick reply to this message  
Reply


This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 295 | Replies: 2
Thread Tools Search this Thread



Tag cloud for countingeverycharactersfromastring
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC