5
19/10/2024 8:41 am
Início do tópico
On the first line you will receive a string. On the second line you will receive a second string. Write a program that removes all of the occurrences of the first string in the second until there is no match. At the end print the remaining string.
Examples:

3 Respostas
4
19/10/2024 9:35 am
My solution:
<?php
$replacement = readline();
$str = readline();
$count = 1;
while ($count > 0) {
$strNew = str_replace($replacement, "", $str, $count);
if ($str == $strNew) {
break;
} else {
$str = $strNew;
}
}
echo $strNew;
3
19/10/2024 9:38 am
This is mine code:
<?php
$replacement = readline();
$str = readline();
while (true) {
$strNew = str_replace($replacement, "", $str);
if ($str == $strNew) {
break;
} else {
$str = $strNew;
}
}
echo $strNew;
1
19/10/2024 9:40 am
This one is mine:
<?php
$replacement = readline();
$str = readline();
while (strpos($str, $replacement) !== false) {
$str = str_replace($replacement, "", $str);
}
echo $str;
