Home » PHP » PHP Ctype functions

PHP ctype_space() function with example

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

PHP ctype_space() function

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

Note: Whitespace contains some of the other things like "tabs" (horizontal, vertical), "line feed", "carriage return", and "form feed".

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

Syntax:

    ctype_space(string) : bool

Example:

    Input: "\r\n"
    Output: true
    Input: " "
    Output: true
    Input: "Hello world"
    Output: false

PHP code:

<?php
    $str = " ";
    if(ctype_space($str))
        echo ("$str contains whitespaces.\n");
    else
        echo ("$str does not contain whitespaces.\n");

    $str = "\r\n";
    if(ctype_space($str))
        echo ("$str contains whitespaces.\n");
    else
        echo ("$str does not contain whitespaces.\n");

    $str = "Hello world123";
    if(ctype_space($str))
        echo ("$str contains whitespaces.\n");
    else
        echo ("$str does not contain whitespaces.\n");

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

Output

  contains whitespaces.

 contains whitespaces.
Hello world123 does not contain whitespaces.
[email protected]&a does not contain whitespaces.





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




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.