Author Topic: If it has alphabetic  (Read 646 times)

0 Members and 1 Guest are viewing this topic.

Offline egturnkeyTopic starter

  • Enthusiast
  • Posts: 89
    • View Profile
If it has alphabetic
« on: March 17, 2010, 08:31:46 AM »
Hello friends,

If we have the following

$manal "hate1";

i wanna say if $manal has alphabetic letters ( not only digits ) then show something else then show anything


if xxxxxxxx {
  echo 
'something';
} else {
echo 
'anything';
}



xxxxxx is the part i can't write, it want it means if $manal has letter and not digits

hope you got what i mean,

thanks so much
« Last Edit: March 17, 2010, 08:32:21 AM by egturnkey »

Offline JAY6390

  • Devotee
  • Posts: 804
  • Gender: Male
  • Not suitable for adults
    • View Profile
    • Jay Gilford
Re: If it has alphabetic
« Reply #1 on: March 18, 2010, 04:00:48 AM »
if(!preg_match('/^\d+$/'$manal) {
 ...
}

Offline Mchl

  • Staff Alumni
  • Freak!
  • *
  • Posts: 8,582
  • Gender: Male
  • That's Largo in my avatar, not me.
    • View Profile
    • FlingBits
Re: If it has alphabetic
« Reply #2 on: March 18, 2010, 04:35:00 AM »
^\d will accept also non-letter characters.

Code: [Select]
if(!preg_match('/[a-zA-Z]+$/', $manal) {
 ...
}
NetBeans fanatic | ExtJS masochist | C++ denier
PHP4 & MySQL4 are no longer supported.
PHPFreaks Tutorials | PHP Debugging: A Beginner's guide | PHP Security Tutorial || How To Ask Questions The Smart Way
Flingbits tutorials | Class Autoloading

Online The Little Guy

  • Freak!
  • Posts: 6,100
  • Gender: Male
  • Jinkies!
    • View Profile
    • PHPSnips
Re: If it has alphabetic
« Reply #3 on: March 19, 2010, 01:08:11 AM »
Is this what your looking for?
Code: [Select]
<?php
$strings 
= array('AbCd1zyZ9''foo!#$bar');
foreach (
$strings as $testcase) {
    if (
ctype_alnum($testcase)) {
        echo 
"The string $testcase consists of all letters or digits.\n";
    } else {
        echo 
"The string $testcase does not consist of all letters or digits.\n";
    }
}
?>
phpLive - A powerful library that implements many common tasks to make php programming faster. Supports extensions and plugins. Current version: 1.0.0-Alpha
JPG to ASCII Converter | Advanced Image CAPTCHA | Simple User Login | Check If User Is Logged In
http://dreamhost.com (promo code: 8RN4)
$30 off 1 year of hosting
$40 off 2 years of hosting

Offline Mchl

  • Staff Alumni
  • Freak!
  • *
  • Posts: 8,582
  • Gender: Male
  • That's Largo in my avatar, not me.
    • View Profile
    • FlingBits
Re: If it has alphabetic
« Reply #4 on: March 19, 2010, 05:58:36 AM »
@TLG: If anything, it seems he wants ctype_alpha()
NetBeans fanatic | ExtJS masochist | C++ denier
PHP4 & MySQL4 are no longer supported.
PHPFreaks Tutorials | PHP Debugging: A Beginner's guide | PHP Security Tutorial || How To Ask Questions The Smart Way
Flingbits tutorials | Class Autoloading

Offline JAY6390

  • Devotee
  • Posts: 804
  • Gender: Male
  • Not suitable for adults
    • View Profile
    • Jay Gilford
Re: If it has alphabetic
« Reply #5 on: March 19, 2010, 06:11:08 AM »
The regex option seems a lot simpler to me lol

Online The Little Guy

  • Freak!
  • Posts: 6,100
  • Gender: Male
  • Jinkies!
    • View Profile
    • PHPSnips
Re: If it has alphabetic
« Reply #6 on: March 19, 2010, 01:47:05 PM »
@TLG: If anything, it seems he wants ctype_alpha()

When I read his post, it just sounded like he wanted numbers and letters, maybe i was wrong...
phpLive - A powerful library that implements many common tasks to make php programming faster. Supports extensions and plugins. Current version: 1.0.0-Alpha
JPG to ASCII Converter | Advanced Image CAPTCHA | Simple User Login | Check If User Is Logged In
http://dreamhost.com (promo code: 8RN4)
$30 off 1 year of hosting
$40 off 2 years of hosting

Offline Mchl

  • Staff Alumni
  • Freak!
  • *
  • Posts: 8,582
  • Gender: Male
  • That's Largo in my avatar, not me.
    • View Profile
    • FlingBits
Re: If it has alphabetic
« Reply #7 on: March 19, 2010, 07:06:34 PM »
Yeah... he writes basically two different thing in two places.
NetBeans fanatic | ExtJS masochist | C++ denier
PHP4 & MySQL4 are no longer supported.
PHPFreaks Tutorials | PHP Debugging: A Beginner's guide | PHP Security Tutorial || How To Ask Questions The Smart Way
Flingbits tutorials | Class Autoloading