PHP 中的 ctype_digit()函数

首页 / PHP入门教程 / PHP 中的 ctype_digit()函数

ctype_digit() - 语法

ctype_digit ( $text );

它检查提供的字符串text中的所有字符是否都是数字的。它只检查1.9

Sr.No Parameter & Description
1

text(必需)

匹配字符串。

ctype_digit() - 返回值

如果文本中的每个字符都是十进制数字,则返回TRUE,否则返回FALSE。

链接:https://www.learnfk.comhttps://www.learnfk.com/php/php-function-ctype-digit.html

来源:LearnFk无涯教程网

ctype_digit() - 示例

<?php
   $strings=array('122.50', '1004', 'foo!#$bar');
   
   foreach ($strings as $test) {
      if (ctype_digit($test)) {
         echo "$test consists of all digits.\n";
      }else {
         echo "$test does not have all digits.\n";
      }
   }
?> 

这将产生以下结果-

122.50 does not have all digits
1004 consists of all digits
foo!#$bar does not have all digits

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

算法面试通关40讲 -〔覃超〕

后端技术面试 38 讲 -〔李智慧〕

Java业务开发常见错误100例 -〔朱晔〕

编译原理实战课 -〔宫文学〕

OAuth 2.0实战课 -〔王新栋〕

Django快速开发实战 -〔吕召刚〕

MySQL 必知必会 -〔朱晓峰〕

Web漏洞挖掘实战 -〔王昊天〕

手把手带你写一个 MiniTomcat -〔郭屹〕

好记忆不如烂笔头。留下您的足迹吧 :)