fork download
  1. <?php
  2.  
  3. $vowels = array('a', 'o', 'u', 'i', 'j', 'e'); // Array of vowels
  4. $uniqueVowels = array(); // Array to store unique vowels
  5. $newString = ""; // String to store the result
  6.  
  7. echo "Enter a string (up to 70 characters): ";
  8. $s1 = fgets(STDIN); // Get the input string
  9.  
  10. $s1 = trim($s1); // Remove leading and trailing spaces
  11.  
  12. if (strlen($s1) > 70) {
  13. echo "Error: String length cannot exceed 70 characters.\n";
  14. }
  15.  
  16. // Check each character in the input string
  17. for ($i = 0; $i < strlen($s1); $i++) {
  18. $char = strtolower($s1[$i]); // Convert character to lowercase
  19.  
  20. // Check if the character is a vowel
  21. if (in_array($char, $vowels)) {
  22. // Check if the vowel is already in the uniqueVowels array
  23. if (!in_array($char, $uniqueVowels)) {
  24. $uniqueVowels[] = $char; // Add the vowel to uniqueVowels
  25. }
  26. }
  27. }
  28.  
  29. // Construct the new string with unique vowels
  30. foreach ($uniqueVowels as $vowel) {
  31. $newString .= $vowel;
  32. }
  33.  
  34. echo "String with unique vowels: " . $newString . "\n";
  35.  
  36. ?>
  37.  
Success #stdin #stdout 0.03s 25880KB
stdin
f d u j k g r j o j m h j a a 
stdout
Enter a string (up to 70 characters): String with unique vowels: ujoa