How to be safe when PHP6 is released and ereg regex turns into extension instead of core

For those of you who don't know what's going to happen in PHP6, here's a nice read: http://jero.net/articles/php6

Now, if you have functions that depend on ereg and have no control over the php.ini file on the server that hosts your scripts, how do you deal with this?

For example, this function is here:

function currentDateTime() {
  list($micro, $Unixtime) = explode(" ",microtime());
  $sec= $micro + date("s", $Unixtime);
  $sec = mb_ereg_replace(sprintf('%d', $sec), "", ($micro + date("s", $Unixtime)));
  return date("Y-m-d H:i:s", $Unixtime).$sec;
}

      

It seems to depend on ereg, so how do you replace that?

+1


a source to share


2 answers


You can rewrite to use preg function .



Edit: dynamic loading seems to be deprecated ...

+8


a source


You can use ini_set()

to set PHP configuration values ​​in your script if you have no control over your file php.ini

. But I recommend going to preg_

via at some point ereg_

. PCRE is much more useful and powerful than POSIX regular expressions, and is largely compatible.



+1


a source







All Articles