Home » PHP » PHP Ctype functions

PHP ctype_alpha() function with example

PHP ctype_alpha() function: Here, we are going to learn about the ctype_alpha() function with example in PHP.
Submitted by IncludeHelp, on February 04, 2019

PHP ctype_alpha() function

ctype_alpha() function is a character type (CType) function in PHP, it is used to check whether a given string contains only alphabets or not.

It returns true – if the string contains only alphabets, else it returns false.

Syntax:

    ctype_alpha(string) : bool

Example:

    Input: "Hello"
    Output: true
    Input: "Hello123"
    Output: false
    Input: "[email protected]&a"
    Output: false

PHP code:

<?php
    $str = "Hello";
    if(ctype_alpha($str))
        echo ("$str contains only alphabets.\n");
    else
        echo ("$str does not contain only alphabets.\n");

    $str = "Hello123";
    if(ctype_alpha($str))
        echo ("$str contains only alphabets.\n");
    else
        echo ("$str does not contain only alphabets.\n");

    $str = "Hello world";
    if(ctype_alpha($str))
        echo ("$str contains only alphabets.\n");
    else
        echo ("$str does not contain only alphabets.\n");

    $str = "[email protected]&a";
    if(ctype_alpha($str))
        echo ("$str contains only alphabets.\n");
    else
        echo ("$str does not contain only alphabets.\n");
?>

Output

Hello contains only alphabets.
Hello123 does not contain only alphabets.
Hello world does not contain only alphabets.
[email protected]&a does not contain only alphabets.





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.