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。

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

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

技术教程推荐

Python核心技术与实战 -〔景霄〕

透视HTTP协议 -〔罗剑锋(Chrono)〕

Linux实战技能100讲 -〔尹会生〕

Elasticsearch核心技术与实战 -〔阮一鸣〕

编辑训练营 -〔总编室〕

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

动态规划面试宝典 -〔卢誉声〕

恋爱必修课 -〔李一帆〕

给程序员的写作课 -〔高磊〕

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