PhpDig.net

What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.




is_numeric

Name

is_numeric — Tests whether a value is a number or a numeric string.

Synopsis

bool is_numeric(value);
mixed value: Value or variable to test

Returns

TRUE if the value is a numeric value; FALSE otherwise

Description

is_numeric() checks whether value is a number or a numeric string. If so, the function returns TRUE. If not, FALSE is returned.

The function recognizes any normal numeric value, as well as numbers that are represented in scientific notation (such as 8.79e-43), in octal base notation (such as 01000 or 02177), or in hexadecimal base notation (such as 0x0FFor0xODE).

It also recognizes numbers contained within strings - however, the string must contain only a number. Any characters that are not part of a valid number will cause the function to assume that the string is not a number. See the example for details.

Version

PHP Version: 3+, 4+

See also

gettype()

Example

Example 1395. Test whether a bunch of values are numeric

<pre>
<?php
// Make a list of the values that we want to convert
$values = array (
    1000 => 1000, '0xFF' => 0xFF, '033' => 033, 'foo' => 'foo', '10,000' => '10,000',
    '1.23456789e10' => 1.23456789e10, '1.22e30' => 1.22e30, '127.0.0.1' => '127.0.0.1',
    '101 uses for an Unemployed dot.commer' => '101 uses for an Unemployed dot.commer'
);


// Loop through the values, testing whether they are numeric or not
foreach ($values as $key => $value) {
                $is_num = is_numeric ($value) ? 'Yes' : 'No';

    printf ("<b>%'.-45s</b>%'.3s\n", "'$key'", $is_num);
}

?>
</pre>



PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.