It seems you just forgot the separator
preg_match("~/$~", $this->library_path)
and
preg_match("~gd2$~i", $protocol)
But in both cases, you should not use regular expressions, because they are much larger
$this->library_path[strlen($this->library_path) - 1] == '/'
substr($protocol, -3) == 'gd2'
source
share