HCProfessionals Posted October 4, 2011 Share Posted October 4, 2011 I have a directory list using variables Folder/ and sub folders with /Folder/, what i need to do is replace the beginning slash if there is one. I'm using a recursive command and if i use substr for example: subtr("$variable", 1); it will always remove the first character. What I need is an if statement or something to check to make sure it is a slash. Quote Link to comment https://forums.phpfreaks.com/topic/248410-substr-help/ Share on other sites More sharing options...
mikesta707 Posted October 4, 2011 Share Posted October 4, 2011 Well you simply check the first index of the string, and compare it to a slash. if it is you are safe to remove it if (!empty($variable) && $variable[0] == "/"){//check if its empty first to avoid possible error substr($variable, 1); } Quote Link to comment https://forums.phpfreaks.com/topic/248410-substr-help/#findComment-1275659 Share on other sites More sharing options...
AbraCadaver Posted October 4, 2011 Share Posted October 4, 2011 ltrim Quote Link to comment https://forums.phpfreaks.com/topic/248410-substr-help/#findComment-1275661 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.