943,779 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 493
  • PHP RSS
Sep 14th, 2009
0

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

Expand Post »
PHP Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 4
Junior Poster
masterjiraya is offline Offline
153 posts
since Jul 2008
Sep 14th, 2009
0

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

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:

PHP Syntax (Toggle Plain Text)
  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. }
Reputation Points: 10
Solved Threads: 2
Light Poster
Rkeast is offline Offline
33 posts
since Aug 2009
Sep 14th, 2009
0

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

You may find using regex in the switch area may be more efficient than multiple case statements.

vowels = [AEIOUaeiou], etc.
Sponsor
Featured Poster
Reputation Points: 1048
Solved Threads: 947
Sarcastic Poster
ardav is offline Offline
6,680 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: how to see the value
Next Thread in PHP Forum Timeline: Fill Function





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC