[ create a new paste ] login | about

Link: http://codepad.org/1Wv59VmO    [ raw code | output | fork ]

PHP, pasted on Oct 5:
<?php

function s2int($pinned_id) { 
echo "/$pinned_id/  ";
if (false === ($x = filter_var(preg_replace('/^0+(\d)/','$1',$pinned_id), FILTER_VALIDATE_INT))) {
    echo "Could not convert $pinned_id to an integer";
    return false;
}
return (int)$pinned_id;
}


echo s2int("000010")."\n";
echo s2int(10.00001)."\n";
echo s2int(10)."\n";
echo s2int("10")."\n";
echo s2int("0")."\n";
echo s2int("a")."\n";
echo s2int("a10")."\n";
echo s2int("10a")."\n";
echo s2int("0x1A")."\n";
echo s2int("-100")."\n";
echo s2int("")."\n";


Output:
1
2
3
4
5
6
7
8
9
10
11
/000010/  10
/10.00001/  Could not convert 10.00001 to an integer
/10/  10
/10/  10
/0/  0
/a/  Could not convert a to an integer
/a10/  Could not convert a10 to an integer
/10a/  Could not convert 10a to an integer
/0x1A/  Could not convert 0x1A to an integer
/-100/  -100
//  Could not convert  to an integer


Create a new paste based on this one


Comments: