How can I use the preg_replace() replace function to only return the parent "component" of a PHP NameSpace?
Basically:
Input: \Base\Ent\User
; Desired Output: Ent
I've been doing this using substr()
but I want to convert it to regex.
Note: Can this be done without preg_match_all()
?
Right now, I also have a code to get all parent components:
$s = '\\Base\\Ent\\User';
print preg_replace('~\\\\[^\\\\]*$~', '', $s);
//=> \Base\Ent
But I only want to return Ent
.
Thank you!