'is substr_replace() in php useless? w3schools [closed]

As in https://www.w3schools.com/php/func_string_substr_replace.asp

<?php
echo substr_replace("Hello","world",0);
?>

where is the needle parameter? if there is non , so what is the point of this function? when will anybody use it? i just can use use $a = "world" instead of $a = sbustr_replace($whatever,"world",0)

Edit: w3schools.com made it seem useless with their example of

<?php
echo substr_replace("Hello","world",0);
?> 
php


Solution 1:[1]

It determines which part of the original string to replace with the replacement based on the start and length arguments.

Since you told it to start at 0 and didn't include a length, it replaces the whole thing.

The function isn't useless, but the way you pass it 0 and nothing as the third and last argument makes it so.

Solution 2:[2]

As per the docs (https://www.php.net/manual/en/function.substr-replace.php) this function is used for replacing part of a string when you know the location of the part of the string you want to change. If you want to locate part of the string first, use something like https://www.php.net/manual/en/function.strpos.php or https://www.php.net/manual/en/function.str-replace.php - this is probably must useful for your use-case: you provide a needle (1st argument) and every occurence of this needle in the original string (3rd argument) be replaced with the 2nd argument

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Quentin
Solution 2 jnko