note 86356 modified in function.is-int by danbrown
| From: | danbrown@php.net | Date: | Tue, 14 Oct 2008 18:57:24 +0000 |
| Subject: | note 86356 modified in function.is-int by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145359@lists.php.net to get a copy of this message | ||
<?php
function onlyNumbers($string){
//This function removes all characters other than numbers
//Esta função limpa a url e conserva apenas os numeros
$string = preg_replace("/[^0-9]/", "", $string);
return (int) $string;
}
echo $test = onlyNumbers("as87d68a6db8a7d686dx8a6dx"); //2147483647
echo "<br/>";
echo onlyNumbers("xn89d9x797d9a8x7-"); //899797987
echo "<br/>";
if(is_int($test)){
echo "Is int ! - Ã inteiro !"; // This OK !
} else {
echo "Not int ! - Não é inteiro";
}
?>
--was--
<?
function onlyNumbers($string){
//Esta função limpa a url e conserva apenas os numeros
//This function clean all other than numbers
$string = preg_replace("/[^0-9]/", "", $string);
return (int) $string;
}
echo $test = onlyNumbers("as87d68a6db8a7d686dx8a6dx"); //2147483647
echo "<br/>";
echo onlyNumbers("xn89d9x797d9a8x7-"); //899797987
echo "<br/>";
if(is_int($test)){
echo "Is int ! - Ã inteiro !"; // This OK !
} else {
echo "Not int ! - Não é inteiro";
}
?>
http://php.net/manual/en/function.is-int.php