WSP Webmaster
WSP Webmaster

Reputation: 35

trying to update split() to explode()

I know very little PHP and I am trying to update code that was written for PHP 5.6 to 7.4.11

From what I understand split() does not work with PHP 7.4.11

I am trying to update the following 5 snips of code where split() is used.

$arrscreenshots = split("\|", $uploadclass->screenshots);

. ' arrid = e.id.split("_");'

. ' var id = e.split("_")[1];'

. ' var arr = e.split("_");'

. ' var myarr = rows[rows.length-1].id.split("_");'

Upvotes: 0

Views: 204

Answers (1)

Alex Howansky
Alex Howansky

Reputation: 53523

Lines 2-5 are not PHP, they're JavaScript. (Even though they're created by PHP code, they're still being run as JavaScript by the browser.)

Line 1 can be changed to use explode(), which doesn't take a regular expression, so you can just use the delimiter directly:

$arrscreenshots = explode("|", $uploadclass->screenshots);

Or preg_split() which does take a regular expression, so you need to format the delimiter appropriately:

$arrscreenshots = preg_split("/\|/", $uploadclass->screenshots);

See https://3v4l.org/pv4Qb

Upvotes: 1

Related Questions