php - RegEx find "../" or "./" -


i trying regex tell me if path contains ./ or ../. check user doesn't beyond area. if input contains period before forward slash wont accepted.

e.g.

/user/selected/path/ - ok  ./user/selected/path/ - failed  ../user/selected/path/ - failed  

the forward slash replaced directory_seperator works unix , windows paths.

use this

if (preg_match('#\.(\.)?/#', $path, $match)) echo "error"; 

if need check ../ or ./ in beginning must use this

if (preg_match('#^\.(\.)?/#', $path, $match)) echo "error"; 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -