php - Detect First Alphabetic Character -
this easier making out looking determine whether entry user form contains alphabetic character "first" letter only.
example user input:
<input type="text" name="faa_id" size="50" value="<?php echo $_post['faa_id']?>" />
example form processing
$faa_id = trim(strtoupper($_request['faa_id'])); if $faa_id = "string character except "n" in first position" { show url-1; } else { show url-2; }
context: data aircraft registration numbers. enter them in our form without default "n" (i.e. 345fr , not n345fr) not registration number start n.
for example eja345 aircraft callsign shown in place of generic n#, not registration number or c-yehe canadian registration number)
i know how strip first letter if "n" don't know how detect if first letters alphabetic.
i suppose need determine if first character alphabetic character first check see if "n".
if not "n", url 1 if "n" url 2
my code hard code url similar this:
example url-1 http://www.trackmyflight/n
example url-2 http://www.trackmyflight/
try out regex, made looking strings expressions (regularexpressions):
$pattern = '/^[nn].*$/';
you can check on regexr.com. type word starts (or doesn't) n , put pattern in box after 'expression'
in php can check http://php.net/preg_match. code should this:
$temp = preg_match($pattern, $faa_id) if($temp === false) { //if error occurs } else { if($temp == 0) { return url1; } else { return url2; } }
Comments
Post a Comment