0

I'm implementing a function that converts float numbers to strings.

function exp2int($exp) {
    list($mantissa, $exponent) = spliti("e", $exp);
    if($exponent=='') return $exp;
    list($int, $dec) = split("\.", $mantissa);
    bcscale (abs($exponent - strlen($dec)));
    return bcmul($mantissa, bcpow("10", $exponent));
}

This is an example:

$n = 2.777777778e-10;
echo exp2int($n);

Returns:

0.0000000002777777778

My server is running Php 5.4, and since split and spliti are deprecated since Php 5.3, I get these messages:

Deprecated: Function spliti() is deprecated
Deprecated: Function split() is deprecated

How can I replace those functions in my exp2int function (without the use of @)? Thanks!

Andres SK
  • 10,779
  • 25
  • 90
  • 152

1 Answers1

3

As the PHP website on split() states:

Tip split() is deprecated as of PHP 5.3.0. preg_split() is the suggested alternative to this function. If you don't require the power of regular expressions, it is faster to use explode(), which doesn't incur the overhead of the regular expression engine.

Similarly for spliti():

Tip spliti() is deprecated as of PHP 5.3.0. preg_split() with the i (PCRE_CASELESS) modifier is the suggested alternative.

Note, however, that explode() takes a delimiter string rather than a regex pattern as an argument.

andy
  • 2,002
  • 1
  • 12
  • 21