[colug-432] PHP code question?
pat at linuxcolumbus.com
pat at linuxcolumbus.com
Sun Dec 20 18:53:02 EST 2015
On 2015-12-20 18:34, Vince Herried wrote:
> I have a set of buttons for each letter of the alphabet
> .
> .
>
> <a href="{_SERVER['PHP_SELF']}?_letterA">F</a>
> <a href="{_SERVER['PHP_SELF']}?_letterB">G</a>
> <a href="{_SERVER['PHP_SELF']}?_letterC">H</a>
> .
> .
>
> I want to respond to the button press and set
> $letter='A';
> if some one presses the button for A, and
> $letter='B';
> if some one presses button for B, etc.
>
> I would rather not write 26 if statements such as
> if (isset($_GET['_letterA'])) {
> $letter='A';
> } else if ......
>
> Is there a way to do this using regular expressions?
>
<?php
$temp = 'A';
if (preg_match('/[a-z]/i', $temp, $match) && strlen($temp) == 1) {
print $match[0];
} else {
print "nope";
}
?>
Pat
More information about the colug-432
mailing list