Grabbing the store code from Magento can be quite easy. The following code has always done the trick for me.
As a developer, sometimes it is essential to check if store code URLs are enabled. Store codes are well known for breaking extensions due to the URL format. If you need to check if store code URLs are enabled you could simply use the following.