You can match it with this regular expression: /^hi$|^hi\s|\shi\s|\shi$/
$test = ['hi', 'hi there', 'high', 'hiho'];
$pattern = '/^hi$|^hi\s|\shi\s|\shi$/';
$matches = [];
foreach ($test as $t) {
var_dump($t);
preg_match($pattern, $t, $matches);
var_dump($matches);
}
Parts explained:
- ^hi$ - your sting is "hi"
- ^hi\s - your string starts with hi: "hi "
- \shi\s - there's a " hi " somewhere in your string
- \shi$ - your string ends with " hi"
Those parts are glued together with pipe "|", which in regex means "or", so the entire expression is matching any one of the parts