How can i remove substring from string by entering first and last character of substring in php
For example in string "Hello my name is John" if i enter 'n' and 's' it should return "Hello my John"... Please Help
How can i remove substring from string by entering first and last character of substring in php
For example in string "Hello my name is John" if i enter 'n' and 's' it should return "Hello my John"... Please Help
/**
* Process function.
* For lack of a better name.
*/
function process($f, $l, $subject)
{
return preg_replace(sprintf('/%s.*?%s/', preg_quote($f), preg_quote($l)), '', $subject);
}
$f = 'n';
$l = 's';
echo process($f, $l, 'Hello my last name is Doe and my first name is John');
Output:
Hello my last Doe at John
I added utility, but it is effectively the same as preg_replace('/n.*?s/', '', $subject)
.