just like i use
substr($sometext, 4, 10)
to select a certain part of a string, how can I remove that certain part from the string using the exact positioning?
You could use two substrings:
$new_string = substr($sometext, 0, 4) . substr($sometext, 10);
$new_text = substr($sometext,0,4) . substr($sometext, 10, strlen($sometext));
$string = "Hello World";
$output = substr($string, strpos($string, "W"));
If you want to remove till the last occurrence, use strrpos instead of strpos.
You can get jiggy with it and use array_splice:
$sometext = 'Hello, worlds! How are ya?';
echo str_splice($sometext, 4, 10); // o, worlds!
function str_splice($input, $offset, $length = 0) {
$chars = str_split($input);
return implode(array_splice($chars, $offset, $length));
}
A much simpler solution would be to use substr_replace with an empty replacement string:
$new_string = substr_replace($sometext, '', 4, 10);