Remove multiple spaces from given string
Write a program to remove the multiple spaces from the given string
String str = “You are a good boy.”
Output: “You are a good boy”
- <?php
-
- //without pattern mach
- $str = "I am a good boy";
- for ($i = 0; $i < $str_length; $i++) {
- && $str_arr[$i] == ' '
- && $str_arr[$i] == $str_arr[$i + 1]) {
- } else {
- continue;
- }
- }
-
- ?>