Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F4765
test.php
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
•
bzimport
Nov 21 2014, 10:07 PM
2014-11-21 22:07:07 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
test.php
View Options
<?php
function
wiki_number_format
(
$value
)
{
preg_match
(
'/
(?P<whole>
\d
?[
\d
,]*)
\.
?(?P<decimal>
\d
?[
\d
]*)
\s
*
(?:
\(
(?P<uncertainty>
\d
+)
\)
)?
\s
*
(?:
\*
(?P<base>
\d
+)
\^
(?P<exponent>
\d
+))?
\s
*
(?P<unit>
\w
*)
/x'
,
$value
,
$matches
);
# Cleanup if needed
$matches
[
'whole'
]
=
str_replace
(
','
,
''
,
$matches
[
'whole'
]
);
$matches
[
'decimal'
]
=
str_replace
(
' '
,
''
,
$matches
[
'decimal'
]
);
# Chopping up
$whole
=
str_split
(
$matches
[
'whole'
],
3
);
$matches
[
'whole'
]
=
implode
(
','
,
$whole
);
$decimal
=
str_split
(
$matches
[
'decimal'
],
3
);
if
(
count
(
$decimal
)
>=
2
&&
strlen
(
end
(
$decimal
)
)
==
1
)
{
$last
=
array_pop
(
$decimal
);
$second_last
=
array_pop
(
$decimal
);
$decimal
[]
=
$second_last
.
$last
;
}
$result
=
$matches
[
'whole'
];
if
(
$decimal
[
0
]
!=
''
)
{
if
(
count
(
$decimal
)
==
1
)
{
$tmp_decimal
=
$decimal
[
0
];
}
else
{
$last_decimals
=
array_splice
(
$decimal
,
1
);
$tmp_decimal
=
implode
(
''
,
array_map
(
create_function
(
'$a'
,
'return "<span style=
\"
margin-left:0.25em
\"
>$a</span>";'
)
,
$last_decimals
)
);
$tmp_decimal
=
$decimal
[
0
]
.
$tmp_decimal
;
}
$result
.=
".$tmp_decimal"
;
}
if
(
$matches
[
'uncertainty'
]
)
{
$result
.=
"($matches[uncertainty])"
;
}
if
(
$matches
[
'base'
]
)
{
$result
.=
" × $matches[base]<sup>$matches[exponent]</sup>"
;
}
if
(
$matches
[
'unit'
]
)
{
$result
.=
" $matches[unit]"
;
}
return
$result
;
}
?>
File Metadata
Details
Attached
Mime Type
text/x-php
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4330
Default Alt Text
test.php (1 KB)
Attached To
Mode
T15025: New parser function / magic word, for "pretty-printed" numbers
Attached
Detach File
Event Timeline
Log In to Comment