cs.punk Posted April 5, 2012 Share Posted April 5, 2012 Hey guys. I'm trying to fix this small library's bug. It's having issues when there are special characters in the string name. I'm wondering perhaps if there's a function available to escape it all in one go? My actual question is concerning backslashes. Say we have $dir1 = "\\test\\"; $dir2 = "{test"; In the case that I'm actually looking for a folder with this name, what rules apply say with str replace? What would the search/replace string be for say $dir1, would they be the same by any chance, as the search has characters 'escaped' while the replace is inserting raw text? //Dir 1: Search: \\\\t\\\\ Replace \\\\t\\\\ Quote Link to comment https://forums.phpfreaks.com/topic/260384-escaping-strings-for-glob/ Share on other sites More sharing options...
JAY6390 Posted April 5, 2012 Share Posted April 5, 2012 are you wanting the addslashes() function? Quote Link to comment https://forums.phpfreaks.com/topic/260384-escaping-strings-for-glob/#findComment-1334572 Share on other sites More sharing options...
cs.punk Posted April 5, 2012 Author Share Posted April 5, 2012 are you wanting the addslashes() function? That won't work. It seems glob has this weird sorta regex syntax. For example to escape [ I need to write it as []]. Quote Link to comment https://forums.phpfreaks.com/topic/260384-escaping-strings-for-glob/#findComment-1334725 Share on other sites More sharing options...
DavidAM Posted April 5, 2012 Share Posted April 5, 2012 Did you try using the GLOB_NOESCAPE flag? See the manual for glob Quote Link to comment https://forums.phpfreaks.com/topic/260384-escaping-strings-for-glob/#findComment-1334752 Share on other sites More sharing options...
cs.punk Posted April 6, 2012 Author Share Posted April 6, 2012 Did you try using the GLOB_NOESCAPE flag? See the manual for glob That would disable a blackslash from quoting a metacharecter. Although '\\test' with the flag on would correctly look for a '\test' folder which goes against my logic? Quote Link to comment https://forums.phpfreaks.com/topic/260384-escaping-strings-for-glob/#findComment-1334967 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.