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. 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); } 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 Link to comment https://forums.phpfreaks.com/topic/248410-substr-help/#findComment-1275661 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.