Tutorialspoint.dev

PHP | IntlChar::ispunct() Function

The IntlChar::ispunct() function is an inbuilt function in PHP which is used to check whether the given input character is a punctuation character or not.

Syntax:

bool IntlChar::ispunct( $codepoint )

Paramters: This function accepts single parameter $codepoint which is mandotary. The input parameter is an integer values or character, which is encoded as a UTF-8 string.

Return Value: If $codepoint is a punctuation character then it returns True, otherwise return False.

Below programs illustrate the IntlChar::ispunct() function in PHP:



Program 1:

<?php
// PHP code to illustrate IntlChar::ispunct()
// function
    
// Input data is character type
var_dump(IntlChar::ispunct("G"));
echo "<br>";
   
// Input data is control character
var_dump(IntlChar::ispunct(" "));
echo "<br>";
   
// Input data is string type 
var_dump(IntlChar::ispunct("Geeksforgeeks"));
echo "<br>";
    
// Input data is number type
var_dump(IntlChar::ispunct("2018"));
echo "<br>";
    
// Input data is single digit
var_dump(IntlChar::ispunct("5"));
echo "<br>";
  
// Input data is punctuation character dot
var_dump(IntlChar::ispunct("."));
echo "<br>";
  
// Input data is punctuation character comma
var_dump(IntlChar::ispunct(","));
echo "<br>";
   
?>

/div>

Output:

bool(false) 
bool(false) 
NULL 
NULL 
bool(false) 
bool(true) 
bool(true) 

Note: If String and Numbers (except single digit number) are used as a parameter then it returns NULL.

Program 2:

<?php
// PHP code to illustrate ispunct()
       
// Declare an array $arr
$arr = array("&", "%", "@", "!", "(", ")", ".", ",", "/", "G", "0");
      
// Loop run for every array element
foreach ($arr as $val){
          
    // Check each element as code point data
    var_dump(IntlChar::ispunct($val));
    echo "<br>";
}
?>

Output:

bool(true) 
bool(true) 
bool(true) 
bool(true) 
bool(true) 
bool(true) 
bool(true) 
bool(true) 
bool(true) 
bool(false) 
bool(false) 

Related Articles:

Reference: http://php.net/manual/en/intlchar.ispunct.php



This article is attributed to GeeksforGeeks.org

You Might Also Like

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter