note 120033 added to function.preg-match

From: Date: Wed, 12 Oct 2016 23:09:02 +0000
Subject: note 120033 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-206868@lists.php.net to get a copy of this message
To validate directorys on Windows i used this: if( preg_match("#^([a-z]{1}\:{1})?[\\\/]?([\-\w]+[\\\/]?)*$#i",$_GET['path'],$matches) !== 1 ){ echo("Invalid value"); }else{ echo("Valid value"); } The parts are: #^ and $i Make the string matches at all the pattern, from start to end for ensure a complete match. ([a-z]{1}\:{1})? The string may starts with one letter and a colon, but only 1 character for eachone, this is for the drive letter (C:) [\\\/]? The string may contain, but not require 1 slash or backslash after the drive letter, (\/) ([\-\w]+[\\\/]?)* The string must have 1 or more of any character like hyphen, letter, number, underscore, and may contain a slash or back slash at the end, to have a directory like ("/" or "folderName" or "folderName/"), this may be repeated one or more times. ---- Server IP: 72.52.91.14 Probable Submitter: 201.105.17.4 ---- Manual Page -- http://php.net/manual/en/function.preg-match.php Edit -- https://master.php.net/note/edit/120033 Del: integrated -- https://master.php.net/note/delete/120033/integrated Del: useless -- https://master.php.net/note/delete/120033/useless Del: bad code -- https://master.php.net/note/delete/120033/bad+code Del: spam -- https://master.php.net/note/delete/120033/spam Del: non-english -- https://master.php.net/note/delete/120033/non-english Del: in docs -- https://master.php.net/note/delete/120033/in+docs Del: other reasons-- https://master.php.net/note/delete/120033 Reject -- https://master.php.net/note/reject/120033 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#206868) next »