| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
function validateUrlSyntax( $urladdr, $options="" ){ |
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
// DISABLED PERMAMENTLY - OK to remove from code |
|---|
| 174 |
// $options = strtolower($options); |
|---|
| 175 |
|
|---|
| 176 |
// Check Options Parameter |
|---|
| 177 |
if (!ereg( '^([sHSEFuPaIpfqr][+?-])*$', $options )) |
|---|
| 178 |
{ |
|---|
| 179 |
trigger_error("Options attribute malformed", E_USER_ERROR); |
|---|
| 180 |
} |
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
// Scheme |
|---|
| 184 |
if (strpos( $options, 's') === false) $aOptions['s'] = '?'; |
|---|
| 185 |
else $aOptions['s'] = substr( $options, strpos( $options, 's') + 1, 1); |
|---|
| 186 |
|
|---|
| 187 |
if (strpos( $options, 'H') === false) $aOptions['H'] = '?'; |
|---|
| 188 |
else $aOptions['H'] = substr( $options, strpos( $options, 'H') + 1, 1); |
|---|
| 189 |
|
|---|
| 190 |
if (strpos( $options, 'S') === false) $aOptions['S'] = '?'; |
|---|
| 191 |
else $aOptions['S'] = substr( $options, strpos( $options, 'S') + 1, 1); |
|---|
| 192 |
|
|---|
| 193 |
if (strpos( $options, 'E') === false) $aOptions['E'] = '-'; |
|---|
| 194 |
else $aOptions['E'] = substr( $options, strpos( $options, 'E') + 1, 1); |
|---|
| 195 |
|
|---|
| 196 |
if (strpos( $options, 'F') === false) $aOptions['F'] = '-'; |
|---|
| 197 |
else $aOptions['F'] = substr( $options, strpos( $options, 'F') + 1, 1); |
|---|
| 198 |
|
|---|
| 199 |
if (strpos( $options, 'u') === false) $aOptions['u'] = '?'; |
|---|
| 200 |
else $aOptions['u'] = substr( $options, strpos( $options, 'u') + 1, 1); |
|---|
| 201 |
|
|---|
| 202 |
if (strpos( $options, 'P') === false) $aOptions['P'] = '?'; |
|---|
| 203 |
else $aOptions['P'] = substr( $options, strpos( $options, 'P') + 1, 1); |
|---|
| 204 |
|
|---|
| 205 |
if (strpos( $options, 'a') === false) $aOptions['a'] = '+'; |
|---|
| 206 |
else $aOptions['a'] = substr( $options, strpos( $options, 'a') + 1, 1); |
|---|
| 207 |
|
|---|
| 208 |
if (strpos( $options, 'I') === false) $aOptions['I'] = '?'; |
|---|
| 209 |
else $aOptions['I'] = substr( $options, strpos( $options, 'I') + 1, 1); |
|---|
| 210 |
|
|---|
| 211 |
if (strpos( $options, 'p') === false) $aOptions['p'] = '?'; |
|---|
| 212 |
else $aOptions['p'] = substr( $options, strpos( $options, 'p') + 1, 1); |
|---|
| 213 |
|
|---|
| 214 |
if (strpos( $options, 'f') === false) $aOptions['f'] = '?'; |
|---|
| 215 |
else $aOptions['f'] = substr( $options, strpos( $options, 'f') + 1, 1); |
|---|
| 216 |
|
|---|
| 217 |
if (strpos( $options, 'q') === false) $aOptions['q'] = '?'; |
|---|
| 218 |
else $aOptions['q'] = substr( $options, strpos( $options, 'q') + 1, 1); |
|---|
| 219 |
|
|---|
| 220 |
if (strpos( $options, 'r') === false) $aOptions['r'] = '?'; |
|---|
| 221 |
else $aOptions['r'] = substr( $options, strpos( $options, 'r') + 1, 1); |
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
foreach($aOptions as $key => $value) |
|---|
| 226 |
{ |
|---|
| 227 |
if ($value == '-') |
|---|
| 228 |
{ |
|---|
| 229 |
$aOptions[$key] = '{0}'; |
|---|
| 230 |
} |
|---|
| 231 |
if ($value == '+') |
|---|
| 232 |
{ |
|---|
| 233 |
$aOptions[$key] = ''; |
|---|
| 234 |
} |
|---|
| 235 |
} |
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 |
// echo '<pre>'; print_r($aOptions); echo '</pre>'; |
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
// Preset Allowed Characters |
|---|
| 242 |
$alphanum = '[a-zA-Z0-9]'; |
|---|
| 243 |
$unreserved = '[a-zA-Z0-9_.!~*' . '\'' . '()-]'; |
|---|
| 244 |
$escaped = '(%[0-9a-fA-F]{2})'; |
|---|
| 245 |
$reserved = '[;/?:@&=+$,]'; |
|---|
| 246 |
|
|---|
| 247 |
// Beginning Regular Expression |
|---|
| 248 |
// Scheme - Allows for 'http://', 'https://', 'mailto:', or 'ftp://' |
|---|
| 249 |
$scheme = '('; |
|---|
| 250 |
if ($aOptions['H'] === '') { $scheme .= 'http://'; } |
|---|
| 251 |
elseif ($aOptions['S'] === '') { $scheme .= 'https://'; } |
|---|
| 252 |
elseif ($aOptions['E'] === '') { $scheme .= 'mailto:'; } |
|---|
| 253 |
elseif ($aOptions['F'] === '') { $scheme .= 'ftp://'; } |
|---|
| 254 |
else |
|---|
| 255 |
{ |
|---|
| 256 |
if ($aOptions['H'] === '?') { $scheme .= '|(http://)'; } |
|---|
| 257 |
if ($aOptions['S'] === '?') { $scheme .= '|(https://)'; } |
|---|
| 258 |
if ($aOptions['E'] === '?') { $scheme .= '|(mailto:)'; } |
|---|
| 259 |
if ($aOptions['F'] === '?') { $scheme .= '|(ftp://)'; } |
|---|
| 260 |
$scheme = str_replace('(|', '(', $scheme); |
|---|
| 261 |
} |
|---|
| 262 |
$scheme .= ')' . $aOptions['s']; |
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
// User Info - Allows for 'username@' or 'username:password@'. Note: contrary to rfc, I removed ':' from username section, allowing it only in password. |
|---|
| 266 |
// /---------------- Username -----------------------\ /-------------------------------- Password ------------------------------\ |
|---|
| 267 |
$userinfo = '((' . $unreserved . '|' . $escaped . '|[;&=+$,]' . ')+(:(' . $unreserved . '|' . $escaped . '|[;:&=+$,]' . ')+)' . $aOptions['P'] . '@)' . $aOptions['u']; |
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
$ipaddress = '((((2(([0-4][0-9])|(5[0-5])))|([01]?[0-9]?[0-9]))\.){3}((2(([0-4][0-9])|(5[0-5])))|([01]?[0-9]?[0-9])))'; |
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 |
$domain_tertiary = '(' . $alphanum . '(([a-zA-Z0-9-]{0,62})' . $alphanum . ')?\.)*'; |
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 |
$domain_secondary = '(' . $alphanum . '(([a-zA-Z0-9-]{0,62})' . $alphanum . ')?\.)'; |
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
// Top Level Domain - First character must be Alpha. Last character must be AlphaNumeric. Hyphens are allowed inside. |
|---|
| 280 |
$domain_toplevel = '([a-zA-Z](([a-zA-Z0-9-]*)[a-zA-Z0-9])?)'; |
|---|
| 281 |
*/ |
|---|
| 282 |
|
|---|
| 283 |
// Top Level Domain - Required - Domain List Current As Of December 2004. Use above escaped line to be forgiving of possible future TLD's |
|---|
| 284 |
$domain_toplevel = '(aero|biz|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|post|pro|travel|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ax|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)'; |
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
if ($aOptions['I'] === '{0}') { |
|---|
| 289 |
$address = '(' . $domain_tertiary . $domain_secondary . $domain_toplevel . ')'; |
|---|
| 290 |
} elseif ($aOptions['I'] === '') { |
|---|
| 291 |
$address = '(' . $ipaddress . ')'; |
|---|
| 292 |
} else { |
|---|
| 293 |
$address = '((' . $ipaddress . ')|(' . $domain_tertiary . $domain_secondary . $domain_toplevel . '))'; |
|---|
| 294 |
} |
|---|
| 295 |
$address = $address . $aOptions['a']; |
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
// (0-59999) |(60000-64999) |(65000-65499) |(65500-65529) |(65530-65535) |
|---|
| 299 |
$port_number = '(:(([0-5]?[0-9]{1,4})|(6[0-4][0-9]{3})|(65[0-4][0-9]{2})|(655[0-2][0-9])|(6553[0-5])))' . $aOptions['p']; |
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
$path = '(/?((;)?(' . $unreserved . '|' . $escaped . '|' . '[:@&=+$,]' . ')+(/)?)*)' . $aOptions['f']; |
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
$querystring = '(\?(' . $reserved . '|' . $unreserved . '|' . $escaped . ')*)' . $aOptions['q']; |
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 |
$fragment = '(#(' . $reserved . '|' . $unreserved . '|' . $escaped . ')*)' . $aOptions['r']; |
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
$regexp = '^' . $scheme . $userinfo . $address . $port_number . $path . $querystring . $fragment . '$'; |
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 |
// echo '<pre>' . htmlentities(wordwrap($regexp,70,"\n",1)) . '</pre>'; |
|---|
| 316 |
|
|---|
| 317 |
// Running the regular expression |
|---|
| 318 |
if (eregi( $regexp, $urladdr )) |
|---|
| 319 |
{ |
|---|
| 320 |
return true; |
|---|
| 321 |
} |
|---|
| 322 |
else |
|---|
| 323 |
{ |
|---|
| 324 |
return false; |
|---|
| 325 |
} |
|---|
| 326 |
|
|---|
| 327 |
} |
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 |
/* |
|---|
| 332 |
About ValidateEmailSyntax(): |
|---|
| 333 |
This function uses the ValidateUrlSyntax() function to easily check the |
|---|
| 334 |
syntax of an email address. It accepts the same options as ValidateURLSyntax |
|---|
| 335 |
but defaults them for email addresses. |
|---|
| 336 |
|
|---|
| 337 |
|
|---|
| 338 |
Usage: |
|---|
| 339 |
validateEmailSyntax( url_to_check[, options]) |
|---|
| 340 |
|
|---|
| 341 |
url_to_check - string - The url to check |
|---|
| 342 |
|
|---|
| 343 |
options - string - A optional string of options to set which parts of |
|---|
| 344 |
the url are required, optional, or not allowed. Each option |
|---|
| 345 |
must be followed by a "+" for required, "?" for optional, or |
|---|
| 346 |
"-" for not allowed. See ValidateUrlSyntax() docs for option list. |
|---|
| 347 |
|
|---|
| 348 |
The default options are changed to: |
|---|
| 349 |
s-H-S-E+F-u+P-a+I-p-f-q-r- |
|---|
| 350 |
|
|---|
| 351 |
This only allows an address of "name@domain". |
|---|
| 352 |
|
|---|
| 353 |
Examples: |
|---|
| 354 |
validateEmailSyntax('george@fakemail.com') |
|---|
| 355 |
validateEmailSyntax('mailto:george@fakemail.com', 's+') |
|---|
| 356 |
validateEmailSyntax('george@fakemail.com?subject=Hi%20George', 'q?') |
|---|
| 357 |
validateEmailSyntax('george@212.198.33.12', 'I?') |
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
Author(s): |
|---|
| 362 |
Rod Apeldoorn - rod(at)canowhoopass(dot)com |
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
Homepage: |
|---|
| 366 |
http://www.canowhoopass.com/ |
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
License: |
|---|
| 370 |
Copyright 2004 - Rod Apeldoorn |
|---|
| 371 |
|
|---|
| 372 |
Released under same license as validateUrlSyntax(). For details, contact me. |
|---|
| 373 |
|
|---|
| 374 |
|
|---|
| 375 |
*/ |
|---|
| 376 |
|
|---|
| 377 |
function validateEmailSyntax( $emailaddr, $options="" ){ |
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 |
if (!ereg( '^([sHSEFuPaIpfqr][+?-])*$', $options )) |
|---|
| 381 |
{ |
|---|
| 382 |
trigger_error("Options attribute malformed", E_USER_ERROR); |
|---|
| 383 |
} |
|---|
| 384 |
|
|---|
| 385 |
|
|---|
| 386 |
// Scheme |
|---|
| 387 |
if (strpos( $options, 's') === false) $aOptions['s'] = '-'; |
|---|
| 388 |
else $aOptions['s'] = substr( $options, strpos( $options, 's') + 1, 1); |
|---|
| 389 |
|
|---|
| 390 |
if (strpos( $options, 'H') === false) $aOptions['H'] = '-'; |
|---|
| 391 |
else $aOptions['H'] = substr( $options, strpos( $options, 'H') + 1, 1); |
|---|
| 392 |
|
|---|
| 393 |
if (strpos( $options, 'S') === false) $aOptions['S'] = '-'; |
|---|
| 394 |
else $aOptions['S'] = substr( $options, strpos( $options, 'S') + 1, 1); |
|---|
| 395 |
|
|---|
| 396 |
if (strpos( $options, 'E') === false) $aOptions['E'] = '?'; |
|---|
| 397 |
else $aOptions['E'] = substr( $options, strpos( $options, 'E') + 1, 1); |
|---|
| 398 |
|
|---|
| 399 |
if (strpos( $options, 'F') === false) $aOptions['F'] = '-'; |
|---|
| 400 |
else $aOptions['F'] = substr( $options, strpos( $options, 'F') + 1, 1); |
|---|
| 401 |
|
|---|
| 402 |
if (strpos( $options, 'u') === false) $aOptions['u'] = '+'; |
|---|
| 403 |
else $aOptions['u'] = substr( $options, strpos( $options, 'u') + 1, 1); |
|---|
| 404 |
|
|---|
| 405 |
if (strpos( $options, 'P') === false) $aOptions['P'] = '-'; |
|---|
| 406 |
else $aOptions['P'] = substr( $options, strpos( $options, 'P') + 1, 1); |
|---|
| 407 |
|
|---|
| 408 |
if (strpos( $options, 'a') === false) $aOptions['a'] = '+'; |
|---|
| 409 |
else $aOptions['a'] = substr( $options, strpos( $options, 'a') + 1, 1); |
|---|
| 410 |
|
|---|
| 411 |
if (strpos( $options, 'I') === false) $aOptions['I'] = '-'; |
|---|
| 412 |
else $aOptions['I'] = substr( $options, strpos( $options, 'I') + 1, 1); |
|---|
| 413 |
|
|---|
| 414 |
if (strpos( $options, 'p') === false) $aOptions['p'] = '-'; |
|---|
| 415 |
else $aOptions['p'] = substr( $options, strpos( $options, 'p') + 1, 1); |
|---|
| 416 |
|
|---|
| 417 |
if (strpos( $options, 'f') === false) $aOptions['f'] = '-'; |
|---|
| 418 |
else $aOptions['f'] = substr( $options, strpos( $options, 'f') + 1, 1); |
|---|
| 419 |
|
|---|
| 420 |
if (strpos( $options, 'q') === false) $aOptions['q'] = '-'; |
|---|
| 421 |
else $aOptions['q'] = substr( $options, strpos( $options, 'q') + 1, 1); |
|---|
| 422 |
|
|---|
| 423 |
if (strpos( $options, 'r') === false) $aOptions['r'] = '-'; |
|---|
| 424 |
else $aOptions['r'] = substr( $options, strpos( $options, 'r') + 1, 1); |
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 |
$newoptions = ''; |
|---|
| 428 |
foreach($aOptions as $key => $value) |
|---|
| 429 |
{ |
|---|
| 430 |
$newoptions .= $key . $value; |
|---|
| 431 |
} |
|---|
| 432 |
|
|---|
| 433 |
|
|---|
| 434 |
// echo '<pre>' . $newoptions . '</pre>'; |
|---|
| 435 |
|
|---|
| 436 |
// Send to validateUrlSyntax() and return result |
|---|
| 437 |
return validateUrlSyntax( $emailaddr, $newoptions); |
|---|
| 438 |
|
|---|
| 439 |
} |
|---|
| 440 |
|
|---|
| 441 |
|
|---|
| 442 |
|
|---|
| 443 |
/* |
|---|
| 444 |
About ValidateFtpSyntax(): |
|---|
| 445 |
This function uses the ValidateUrlSyntax() function to easily check the |
|---|
| 446 |
syntax of an FTP address. It accepts the same options as ValidateURLSyntax |
|---|
| 447 |
but defaults them for FTP addresses. |
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
Usage: |
|---|
| 451 |
validateFtpSyntax( url_to_check[, options]) |
|---|
| 452 |
|
|---|
| 453 |
url_to_check - string - The url to check |
|---|
| 454 |
|
|---|
| 455 |
options - string - A optional string of options to set which parts of |
|---|
| 456 |
the url are required, optional, or not allowed. Each option |
|---|
| 457 |
must be followed by a "+" for required, "?" for optional, or |
|---|
| 458 |
"-" for not allowed. See ValidateUrlSyntax() docs for option list. |
|---|
| 459 |
|
|---|
| 460 |
The default options are changed to: |
|---|
| 461 |
s?H-S-E-F+u?P?a+I?p?f?q-r- |
|---|
| 462 |
|
|---|
| 463 |
Examples: |
|---|
| 464 |
validateFtpSyntax('ftp://netscape.com') |
|---|
| 465 |
validateFtpSyntax('moz:iesucks@netscape.com') |
|---|
| 466 |
validateFtpSyntax('ftp://netscape.com:2121/browsers/ns7/', 'u-') |
|---|
| 467 |
|
|---|
| 468 |
|
|---|
| 469 |
Author(s): |
|---|
| 470 |
Rod Apeldoorn - rod(at)canowhoopass(dot)com |
|---|
| 471 |
|
|---|
| 472 |
|
|---|
| 473 |
Homepage: |
|---|
| 474 |
http://www.canowhoopass.com/ |
|---|
| 475 |
|
|---|
| 476 |
|
|---|
| 477 |
License: |
|---|
| 478 |
Copyright 2004 - Rod Apeldoorn |
|---|
| 479 |
|
|---|
| 480 |
Released under same license as validateUrlSyntax(). For details, contact me. |
|---|
| 481 |
*/ |
|---|
| 482 |
|
|---|
| 483 |
function validateFtpSyntax( $ftpaddr, $options="" ){ |
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
if (!ereg( '^([sHSEFuPaIpfqr][+?-])*$', $options )) |
|---|
| 487 |
{ |
|---|
| 488 |
trigger_error("Options attribute malformed", E_USER_ERROR); |
|---|
| 489 |
} |
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 |
// Scheme |
|---|
| 493 |
if (strpos( $options, 's') === false) $aOptions['s'] = '?'; |
|---|
| 494 |
else $aOptions['s'] = substr( $options, strpos( $options, 's') + 1, 1); |
|---|
| 495 |
|
|---|
| 496 |
if (strpos( $options, 'H') === false) $aOptions['H'] = '-'; |
|---|
| 497 |
else $aOptions['H'] = substr( $options, strpos( $options, 'H') + 1, 1); |
|---|
| 498 |
|
|---|
| 499 |
if (strpos( $options, 'S') === false) $aOptions['S'] = '-'; |
|---|
| 500 |
else $aOptions['S'] = substr( $options, strpos( $options, 'S') + 1, 1); |
|---|
| 501 |
|
|---|
| 502 |
if (strpos( $options, 'E') === false) $aOptions['E'] = '-'; |
|---|
| 503 |
else $aOptions['E'] = substr( $options, strpos( $options, 'E') + 1, 1); |
|---|
|
|---|