What kind of phone do you have? This seems to happen to Sony Xperias pretty often because one of the volume buttons has broken. Assuming the buttons are working, you can usually get out of safe mode by doing a hard reboot. It can vary from device to device but usually you just hold down power and volume down (sometimes it’s volume up) until it powers off. Be a little patient, it may take 10-15 seconds. When the device restarts, it should be out of safe mode.