Page 1 of 1
check for single alphabet character
Posted: Sat Sep 15, 2007 8:18 am
by kkonline
I am making a article manager which displays all the articles according to the alphabetical order. If pages.php?alphabet=b then all the titles starting with b will be displayed. In doing so i need to make sure that
only one alphabet is input example pages.php?alphabet=b or pages.php?alphabet=t and the character can be a-z
incase of numbers i used
and wondering what to use to check SINGLE alphabetical character (a to z)??
Posted: Sat Sep 15, 2007 8:22 am
by VladSun
Code: Select all
if (preg_match('/^[a-z]$/', $_GET['page']))
{
echo "OK";
}
^: This is the "beginning of line" symbol
$: This is the "end of line" symbol.
Posted: Sat Sep 15, 2007 8:29 am
by kkonline
VladSun wrote:Code: Select all
if (preg_match('/^[a-z]$/', $_GET['page']))
{
echo "OK";
}
^: This is the "beginning of line" symbol
$: This is the "end of line" symbol.
i used something like
Code: Select all
if(ctype_alpha($_GET['alphabet']) && strlen($_GET['alphabet']<2))
but if i give alphabet=the then also it displays the articles starting with "the" . Whats wrong? with my code logic
Posted: Sat Sep 15, 2007 8:31 am
by feyd
Look closely at your strlen() bit.
Posted: Sat Sep 15, 2007 8:39 am
by kkonline
feyd wrote:Look closely at your strlen() bit.
feyd i figured it out. It should be
Code: Select all
if(ctype_alpha($_GET['alphabet']) && strlen($_GET['alphabet'])<2)