php - Check if directory path ends with DIRECTORY_SEPARATOR -
In PHP, I am getting a string from the user for the local file directory
$ path
I want to know if they have not added the previous slash (/) or I would like it for a cross platform so that I use PHP continuous DIRECTORY_SEPARATOR
Would like to do My unsuccessful attempts include preg_match such as
preg_match ("/". DIRECTORY_SEPARATOR. "$ /", $ Path);
I basically want a great way to test this if the string DIRECTORY_SEPARATOR
.
To fix your regexp:
preg_match (" / ".preg_quote (DIRECTORY_SEPARATOR." $ / ", $ Path);
But there are simple ways to achieve your goal:
rtrim ($ path, DIRECTORY_SEPARATOR) .DIRECTORY_SEPARATOR;
Comments
Post a Comment