note 82250 added to function.ereg
| From: | JohnThur at osu1 dot php dot net | Date: | Wed, 02 Apr 2008 19:29:34 +0000 |
| Subject: | note 82250 added to function.ereg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137865@lists.php.net to get a copy of this message | ||
<?php
function fractionstr2decimal($fs){
if (is_numeric($fs)){
return $fs;
} elseif (ereg ("([0-9]{1,6}[ ])?([0-9]{1,6})\/([0-9]{0,6}[1-9][0-9]{0,6})", $fs,
$regs)) {
/* ({1-6 digits}space optional) {1-6 digits}/(1-13 digits with at least one digit not 0 )*/
return ($regs[1]+$regs[2]/$regs[3]);
} else {
return (NULL); /* Invalid Fraction */
}
}
echo fractionstr2decimal("1024 5/132")."<br>"; /* 1024.0378787879 */
echo fractionstr2decimal("23")."<br>"; /* 23 */
$i=fractionstr2decimal("1 2/3");
echo "<br>$i"; /* 1.66666666666667 */
if ($i and $i<=1 ) echo "<1<br>"; /* */
$i=fractionstr2decimal("2/3");
echo "<br>$i"; /* 0.66666666666667 */
if ($i and $i<=1 ) echo "<1<br>"; /* <1 */
$i=fractionstr2decimal("2/0");
echo "<br>$i";
if ($i and $i<=1 ) echo "<1<br>";
?>
----
Server IP: 208.69.120.35
Probable Submitter: 67.52.25.79
----
Manual Page -- http://www.php.net/manual/en/function.ereg.php
Edit -- https://master.php.net/note/edit/82250
Del: integrated -- https://master.php.net/note/delete/82250/integrated
Del: useless -- https://master.php.net/note/delete/82250/useless
Del: bad code -- https://master.php.net/note/delete/82250/bad+code
Del: spam -- https://master.php.net/note/delete/82250/spam
Del: non-english -- https://master.php.net/note/delete/82250/non-english
Del: in docs -- https://master.php.net/note/delete/82250/in+docs
Del: other reasons-- https://master.php.net/note/delete/82250
Reject -- https://master.php.net/note/reject/82250
Search -- https://master.php.net/manage/user-notes.php