check for single alphabet character

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

check for single alphabet character

Post 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

Code: Select all

if(ctype_digit($_GET['page'])){}
and wondering what to use to check SINGLE alphabetical character (a to z)??
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Look closely at your strlen() bit.
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Post 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)
Post Reply