I have a little issue and I don't know how to call it :D So I want to (simply) remove everything before and after character separated by space. For example:
Input: "Hello holy world"
Key: "ho"
or "hol"
etc.
Output: "holy"
or
Input: "testing text"
Key: "tex"
Output: "text"
Your not removing so much as searching and displaying the match.
$search ='ho';
$str='Hello holy world';
preg_match("/\w*$search\w*/", $str,$out);
print_r($out);
Array
(
[0] => holy
)
\w*
matches any word character (equal to [a-zA-Z0-9_])
demo:https://regex101.com/r/iX3nF6/22 lets you experiment with other strings\options