P
P
Polina Titova2018-04-08 12:36:09
PHP
Polina Titova, 2018-04-08 12:36:09

How to write a function that returns a string without the deleted character?

Prompt with code.
This code should remove the passed character, which is in the variable $simof the string, which is in the variable $str, using a loop and a condition in it, but I cannot make this character be removed from the string.
I am trying to remove a character using decriment.
As I understand it, you need to do something like this:

<?

function filterString($str, $sim) {
    $index = strlen($str);

    while($sim != $index) {
        if($sim === $index) {
            return —$sim;
        } else {
           return $str;
        }

        return —$sim;
    }
}
filterString('Hello world', 'l');

To which variable should I decrement, that is, should I decrement a string or a character?
I am inclined to the option that we need to take out the symbol, because we are deleting it.
Am I on the right track, if not, correct me?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2018-04-08
@politon

<?php
$t1 = str_replace("l", "", "Hello World");
echo $t1;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question