Mustapha George
Mustapha George

Reputation: 2527

php explode / split - co-existence in single script

I have php two servers with different versions of php, and am having trouble with split statement which seems to be deprecated on new box. I replaced with explode which is not known to old box.

$connect = explode(";", DB_CONNECT);

$connect =  split(";", DB_CONNECT);

what statement(s) will make both servers happy? Upgrading is not an option tonight.

Upvotes: 0

Views: 207

Answers (4)

Adam Fowler
Adam Fowler

Reputation: 1751

I have not tried this but hopefully it will work. Good luck.

function ultraExplode($del,$arr){
$ver=phpversion();
if ($ver>=5) return explode($del,$arr);
else return split($del,$arr);}

Upvotes: 0

tim
tim

Reputation: 2724

If explode doesnt exist, create it

if (!function_exists('explode')) { 
   function explode($str, $array) {
      return split($str, $array); 
   }
}

Upvotes: 1

Hamish
Hamish

Reputation: 23316

A better option in the short term is to disable the warning until you're able to upgrade your PHP version.

Upvotes: 1

Adam Zalcman
Adam Zalcman

Reputation: 27233

Try preg_split() and preg_match_all(). The latter doesn't return an array, but may fill in an array pass in as third argument.

Upvotes: 0

Related Questions